类org.apache.logging.log4j.util.Supplier源码实例Demo

下面列出了怎么用org.apache.logging.log4j.util.Supplier的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: logging-log4j2   文件: ClockFactory.java
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());
    }
}
 
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;
}
 
源代码3 项目: crate   文件: MockTaskManager.java
@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;
}
 
源代码4 项目: logging-log4j2   文件: LoggerTest.java
@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"));
}
 
源代码5 项目: logging-log4j2   文件: LoggerSupplierTest.java
@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")));
}
 
@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;
}
 
源代码7 项目: logging-log4j2   文件: LoggerSupplierTest.java
@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")));
}
 
源代码8 项目: logging-log4j2   文件: LoggerSupplierTest.java
@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")));
}
 
源代码9 项目: logging-log4j2   文件: LoggerSupplierTest.java
@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")));
}
 
@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();
    }
}
 
@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();
    }
}
 
源代码12 项目: logging-log4j2   文件: LoggerSupplierTest.java
@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")));
}
 
源代码13 项目: crate   文件: SettingsUpdater.java
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
    );
}
 
源代码14 项目: crate   文件: MockTaskManager.java
@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);
}
 
@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();
    }
}
 
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final LogEvent event) {
    final LoggerConfig config = getActiveLoggerConfig(reconfigured);
    try {
        config.log(event);
    } finally {
        config.getReliabilityStrategy().afterLogEvent();
    }
}
 
@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();
    }
}
 
源代码18 项目: logging-log4j2   文件: AbstractLogger.java
@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);
    }
}
 
@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) {
    loggerConfig.log(loggerName, fqcn, location, marker, level, data, t);
}
 
@Override
public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) {
    return this.loggerConfig;
}
 
源代码21 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void info(final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.INFO, null, msgSupplier, t);
}
 
源代码22 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void info(final Marker marker, final Supplier<?> msgSupplier) {
    logIfEnabled(FQCN, Level.INFO, marker, msgSupplier, (Throwable) null);
}
 
源代码23 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void info(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
    logIfEnabled(FQCN, Level.INFO, marker, message, paramSuppliers);
}
 
源代码24 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void log(final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
    logIfEnabled(FQCN, level, marker, message, paramSuppliers);
}
 
源代码25 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void trace(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.TRACE, marker, msgSupplier, t);
}
 
源代码26 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void fatal(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
    logIfEnabled(FQCN, Level.FATAL, marker, message, paramSuppliers);
}
 
源代码27 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void debug(final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.DEBUG, null, msgSupplier, t);
}
 
源代码28 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void warn(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
    logIfEnabled(FQCN, Level.WARN, marker, msgSupplier, t);
}
 
源代码29 项目: logging-log4j2   文件: AbstractLogger.java
@Override
public void warn(final String message, final Supplier<?>... paramSuppliers) {
    logIfEnabled(FQCN, Level.WARN, null, message, paramSuppliers);
}
 
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final LogEvent event) {
    loggerConfig.log(event);
}
 
 类所在包
 类方法
 同包方法