org.apache.logging.log4j.util.Supplier Java Examples

The following examples show how to use org.apache.logging.log4j.util.Supplier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenNlpService.java    From elasticsearch-ingest-opennlp with Apache License 2.0 6 votes vote down vote up
protected OpenNlpService start() {
    StopWatch sw = new StopWatch("models-loading");
    Map<String, String> settingsMap = IngestOpenNlpPlugin.MODEL_FILE_SETTINGS.getAsMap(settings);
    for (Map.Entry<String, String> entry : settingsMap.entrySet()) {
        String name = entry.getKey();
        sw.start(name);
        Path path = configDirectory.resolve(entry.getValue());
        try (InputStream is = Files.newInputStream(path)) {
            nameFinderModels.put(name, new TokenNameFinderModel(is));
        } catch (IOException e) {
            logger.error((Supplier<?>) () -> new ParameterizedMessage("Could not load model [{}] with path [{}]", name, path), e);
        }
        sw.stop();
    }

    if (settingsMap.keySet().size() == 0) {
        logger.error("Did not load any models for ingest-opennlp plugin, none configured");
    } else {
        logger.info("Read models in [{}] for {}", sw.totalTime(), settingsMap.keySet());
    }

    return this;
}
 
Example #2
Source File: ClockFactory.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private static Clock createClock() {
    final String userRequest = PropertiesUtil.getProperties().getStringProperty(PROPERTY_NAME);
    if (userRequest == null) {
        LOGGER.trace("Using default SystemClock for timestamps.");
        return logSupportedPrecision(new SystemClock());
    }
    Supplier<Clock> specified = aliases().get(userRequest);
    if (specified != null) {
        LOGGER.trace("Using specified {} for timestamps.", userRequest);
        return logSupportedPrecision(specified.get());
    }
    try {
        final Clock result = Loader.newCheckedInstanceOf(userRequest, Clock.class);
        LOGGER.trace("Using {} for timestamps.", result.getClass().getName());
        return logSupportedPrecision(result);
    } catch (final Exception e) {
        final String fmt = "Could not create {}: {}, using default SystemClock for timestamps.";
        LOGGER.error(fmt, userRequest, e);
        return logSupportedPrecision(new SystemClock());
    }
}
 
Example #3
Source File: SettingsUpdater.java    From crate with Apache License 2.0 6 votes vote down vote up
private void logInvalidSetting(
        final String settingType, final Map.Entry<String, String> e, final IllegalArgumentException ex, final Logger logger) {
    logger.warn(
        (Supplier<?>) () -> new ParameterizedMessage(
            "ignoring existing invalid {} setting: [{}] with value [{}]; archiving",
            settingType,
            e.getKey(),
            e.getValue()),
        ex
    );
}
 
Example #4
Source File: MockTaskManager.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Task register(String type, String action, TaskAwareRequest request) {
    Task task = super.register(type, action, request);
    for (MockTaskManagerListener listener : listeners) {
        try {
            listener.onTaskRegistered(task);
        } catch (Exception e) {
            logger.warn(
                (Supplier<?>) () -> new ParameterizedMessage(
                    "failed to notify task manager listener about registering the task with id {}",
                    task.getId()),
                e);
        }
    }
    return task;
}
 
Example #5
Source File: LoggerTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void flowTracingString_SupplierOfStrings() {
    final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<String>() {
        @Override
        public String get() {
            return "1";
        }
    }, new Supplier<String>() {
        @Override
        public String get() {
            return "2";
        }
    });
    logger.traceExit(msg, 3);
    assertEquals(2, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)"));
    assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit"));
    assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3"));
}
 
Example #6
Source File: LockingReliabilityStrategy.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn,
        final StackTraceElement location, final Marker marker, final Level level, final Message data,
        final Throwable t) {
    final LoggerConfig config = getActiveLoggerConfig(reconfigured);
    try {
        config.log(loggerName, fqcn, location, marker, level, data, t);
    } finally {
        config.getReliabilityStrategy().afterLogEvent();
    }
}
 
Example #7
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier,
        final Throwable t) {
    if (isEnabled(level, marker, msgSupplier, t)) {
        logMessage(fqcn, level, marker, msgSupplier, t);
    }
}
 
Example #8
Source File: LoggerSupplierTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void flowTracing_SupplierOfMessageFormatMessage() {
    logger.traceEntry(new Supplier<MessageFormatMessage>() {
        @Override
        public MessageFormatMessage get() {
            return new MessageFormatMessage("int foo={0}", 1234567890);
        }
    });
    assertEquals(1, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("(int foo=1,234,567,890)"));
    assertThat("Bad toString()", results.get(0), not(containsString("MessageFormatMessage")));
}
 
Example #9
Source File: AwaitCompletionReliabilityStrategy.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) {
    LoggerConfig result = this.loggerConfig;
    if (!beforeLogEvent()) {
        result = next.get();
        return result == this.loggerConfig ? result : result.getReliabilityStrategy().getActiveLoggerConfig(next);
    }
    return result;
}
 
Example #10
Source File: LockingReliabilityStrategy.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final LogEvent event) {
    final LoggerConfig config = getActiveLoggerConfig(reconfigured);
    try {
        config.log(event);
    } finally {
        config.getReliabilityStrategy().afterLogEvent();
    }
}
 
Example #11
Source File: AwaitCompletionReliabilityStrategy.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn,
        final Marker marker, final Level level, final Message data, final Throwable t) {

    final LoggerConfig config = getActiveLoggerConfig(reconfigured);
    try {
        config.log(loggerName, fqcn, marker, level, data, t);
    } finally {
        config.getReliabilityStrategy().afterLogEvent();
    }
}
 
Example #12
Source File: LoggerSupplierTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void flowTracing_SupplierOfLocalizedMessage() {
    logger.traceEntry(new Supplier<LocalizedMessage>() {
        @Override
        public LocalizedMessage get() {
            return new LocalizedMessage("int foo={}", 1234567890);
        }
    });
    assertEquals(1, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("(int foo=1234567890)"));
    assertThat("Bad toString()", results.get(0), not(containsString("LocalizedMessage")));
}
 
Example #13
Source File: LockingReliabilityStrategy.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn,
        final Marker marker, final Level level, final Message data, final Throwable t) {

    final LoggerConfig config = getActiveLoggerConfig(reconfigured);
    try {
        config.log(loggerName, fqcn, marker, level, data, t);
    } finally {
        config.getReliabilityStrategy().afterLogEvent();
    }
}
 
Example #14
Source File: LoggerSupplierTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void flowTracing_SupplierOfString() {
    logger.traceEntry(new Supplier<String>() {
        @Override
        public String get() {
            return "1234567890";
        }
    });
    assertEquals(1, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("(1234567890)"));
    assertThat("Bad toString()", results.get(0), not(containsString("SimpleMessage")));
}
 
Example #15
Source File: MockTaskManager.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void waitForTaskCompletion(Task task, long untilInNanos) {
    for (MockTaskManagerListener listener : listeners) {
        try {
            listener.waitForTaskCompletion(task);
        } catch (Exception e) {
            logger.warn(
                (Supplier<?>) () -> new ParameterizedMessage(
                    "failed to notify task manager listener about waitForTaskCompletion the task with id {}",
                    task.getId()),
                e);
        }
    }
    super.waitForTaskCompletion(task, untilInNanos);
}
 
Example #16
Source File: LoggerSupplierTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void flowTracing_SupplierOfFormattedMessage() {
    logger.traceEntry(new Supplier<FormattedMessage>() {
        @Override
        public FormattedMessage get() {
            return new FormattedMessage("int foo={}", 1234567890);
        }
    });
    assertEquals(1, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("(int foo=1234567890)"));
    assertThat("Bad toString()", results.get(0), not(containsString("FormattedMessage")));
}
 
Example #17
Source File: OpenNlpThreadSafeTests.java    From elasticsearch-ingest-opennlp with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        ExtractedEntities locations = service.find(city + " is really an awesome city, but others are as well.", "locations");
        // logger.info("Got {}, expected {}, index {}", locations, city, idx);
        if (locations.getEntityValues().size() > 0) {
            result = Iterables.get(locations.getEntityValues(), 0);
        }
    } catch (Exception e) {
        logger.error((Supplier<?>) () -> new ParameterizedMessage("Unexpected exception"), e);
    } finally {
        latch.countDown();
    }
}
 
Example #18
Source File: LoggerSupplierTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void flowTracing_SupplierOfLong() {
    logger.traceEntry(new Supplier<Long>() {
        @Override
        public Long get() {
            return Long.valueOf(1234567890);
        }
    });
    assertEquals(1, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("(1234567890)"));
    assertThat("Bad toString()", results.get(0), not(containsString("SimpleMessage")));
}
 
Example #19
Source File: DefaultLogBuilder.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void log(Supplier<Message> messageSupplier) {
    if (isValid()) {
        logMessage(messageSupplier.get());
    }
}
 
Example #20
Source File: DefaultReliabilityStrategy.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, final Marker marker, final Level level,
        final Message data, final Throwable t) {
    loggerConfig.log(loggerName, fqcn, marker, level, data, t);
}
 
Example #21
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void fatal(final Supplier<?> msgSupplier) {
    logIfEnabled(FQCN, Level.FATAL, null, msgSupplier, (Throwable) null);
}
 
Example #22
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public EntryMessage traceEntry(final Supplier<?>... paramSuppliers) {
    return enter(FQCN, null, paramSuppliers);
}
 
Example #23
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void warn(final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.WARN, null, msgSupplier, t);
}
 
Example #24
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void warn(final String message, final Supplier<?>... paramSuppliers) {
    logIfEnabled(FQCN, Level.WARN, null, message, paramSuppliers);
}
 
Example #25
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void debug(final Marker marker, final Supplier<?> msgSupplier) {
    logIfEnabled(FQCN, Level.DEBUG, marker, msgSupplier, (Throwable) null);
}
 
Example #26
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void info(final Supplier<?> msgSupplier) {
    logIfEnabled(FQCN, Level.INFO, null, msgSupplier, (Throwable) null);
}
 
Example #27
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
protected void logMessage(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier,
        final Throwable t) {
    final Message message = LambdaUtil.getMessage(msgSupplier, messageFactory);
    logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t);
}
 
Example #28
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void warn(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.WARN, marker, msgSupplier, t);
}
 
Example #29
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void log(final Level level, final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, level, marker, msgSupplier, t);
}
 
Example #30
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void debug(final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.DEBUG, null, msgSupplier, t);
}