Java Code Examples for org.slf4j.LoggerFactory#getILoggerFactory()

The following examples show how to use org.slf4j.LoggerFactory#getILoggerFactory() . These examples are extracted from open source projects. 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
@GetMapping("/appinfo/loggers/query")
public Mono<CommonResponseDto> queryLoggers() {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    List<ch.qos.logback.classic.Logger> loggers = loggerContext.getLoggerList();

    List<LoggerInfoDto> loggerInfos = loggers.stream().filter(lm -> {
        return lm.getLevel() != null;
    }).map(lm -> {
        LoggerInfoDto info = new LoggerInfoDto();
        info.setLevel(lm.getLevel() == null ? null : lm.getLevel().toString());
        info.setPath(lm.getName());

        return info;
    }).collect(Collectors.toList());

    return Mono.just(CommonResponseDto.okayWithData(loggerInfos));
}
 
Example 2
Source Project: cubeai   File: LogsResource.java    License: Apache License 2.0 5 votes vote down vote up
@PutMapping("/logs")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Timed
public void changeLevel(@RequestBody LoggerVM jsonLogger) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.getLogger(jsonLogger.getName()).setLevel(Level.valueOf(jsonLogger.getLevel()));
}
 
Example 3
Source Project: chaosblade-exec-jvm   File: LogUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set log level
 *
 * @param level DEBUG
 */
public static void setLogLevel(String level) {
    ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
    if (loggerFactory instanceof LoggerContext) {
        LoggerContext loggerContext = (LoggerContext)loggerFactory;
        Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
        ((ch.qos.logback.classic.Logger)logger).setLevel(Level.toLevel(level));
        return;
    }
    throw new IllegalStateException("not support the log context object");
}
 
Example 4
@Before
public void setUp() throws Exception {

    context = (LoggerContext) LoggerFactory.getILoggerFactory();

    rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);

    level = rootLogger.getLevel();
    rootLogger.setLevel(Level.DEBUG);
    context.addTurboFilter(new XodusFileDataWriterLogLevelModificator());
    context.getLogger("jetbrains.exodus").setLevel(Level.DEBUG);
}
 
Example 5
Source Project: rocketmq-read   File: MQAdminStartup.java    License: Apache License 2.0 5 votes vote down vote up
private static void initLogback() throws JoranException {
    String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV));

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(rocketmqHome + "/conf/logback_tools.xml");
}
 
Example 6
@Before
public void setUp() throws Exception {

    context = (LoggerContext) LoggerFactory.getILoggerFactory();

    rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);

    level = rootLogger.getLevel();
    rootLogger.setLevel(Level.DEBUG);
    context.addTurboFilter(new XodusFileDataWriterLogLevelModificator());
    context.getLogger("jetbrains.exodus").setLevel(Level.DEBUG);
}
 
Example 7
Source Project: cubeai   File: LogsResource.java    License: Apache License 2.0 5 votes vote down vote up
@PutMapping("/logs")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Timed
public void changeLevel(@RequestBody LoggerVM jsonLogger) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.getLogger(jsonLogger.getName()).setLevel(Level.valueOf(jsonLogger.getLevel()));
}
 
Example 8
Source Project: cubeai   File: LogsResource.java    License: Apache License 2.0 5 votes vote down vote up
@PutMapping("/logs")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Timed
public void changeLevel(@RequestBody LoggerVM jsonLogger) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.getLogger(jsonLogger.getName()).setLevel(Level.valueOf(jsonLogger.getLevel()));
}
 
Example 9
Source Project: cubeai   File: LogsResource.java    License: Apache License 2.0 5 votes vote down vote up
@GetMapping("/logs")
@Timed
public List<LoggerVM> getList() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    return context.getLoggerList()
        .stream()
        .map(LoggerVM::new)
        .collect(Collectors.toList());
}
 
Example 10
Source Project: konduit-serving   File: LogUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setLoggingFromClassPath() throws IOException, JoranException {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    loggerContext.reset();
    JoranConfigurator configurator = new JoranConfigurator();
    try(InputStream configStream = new ClassPathResource("logback.xml").getInputStream()){
        configurator.setContext(loggerContext);
        configurator.doConfigure(configStream); // loads logback file
    }
}
 
Example 11
Source Project: rocketmq-4.3.0   File: LogbackTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example 12
/**
 * Sets the trace log to the root logger. Also adds filter, to make sure that
 * the appender which are already defined for HiveMQ are not affected by this logging
 * level change.
 * <p>
 * <b>This will significantly slow down HiveMQ, since the root level loggers Level is changed
 * to the finest logging level!</b>
 *
 * @param filePath the file path
 */
static void setTraceLog(final String filePath) {

    log.info("Creating trace log {}", filePath);

    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Level originalLoggingLevel = logger.getLevel();
    final Iterator<Appender<ILoggingEvent>> appenderIterator = logger.iteratorForAppenders();
    while (appenderIterator.hasNext()) {
        final Appender<ILoggingEvent> next = appenderIterator.next();
        next.addFilter(new PreserveOriginalLoggingLevelFilter(originalLoggingLevel));
    }

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final PatternLayoutEncoder ple = new PatternLayoutEncoder();

    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();

    final FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
    fileAppender.setFile(filePath);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();

    logger.addAppender(fileAppender);
    logger.setLevel(Level.ALL);
    logger.setAdditive(false);
}
 
Example 13
Source Project: rocketmq-4.3.0   File: MQAdminStartup.java    License: Apache License 2.0 5 votes vote down vote up
private static void initLogback() throws JoranException {
    String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV));

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(rocketmqHome + "/conf/logback_tools.xml");
}
 
Example 14
Source Project: flair-engine   File: LogsResource.java    License: Apache License 2.0 5 votes vote down vote up
@GetMapping("/logs")
@Timed
public List<LoggerVM> getList() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    return context.getLoggerList()
        .stream()
        .map(LoggerVM::new)
        .collect(Collectors.toList());
}
 
Example 15
Source Project: cubeai   File: LogsResourceIntTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testLogstashAppender() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    assertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.class);
}
 
Example 16
public Slf4jLoggerFactory() {
    LoggerFactory.getILoggerFactory();
    doRegister();
}
 
Example 17
Source Project: cubeai   File: LogsResourceIntTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testLogstashAppender() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    assertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.class);
}
 
Example 18
Source Project: rsc   File: Rsc.java    License: Apache License 2.0 4 votes vote down vote up
static void configureDebugLevel(String loggerName) {
	final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	final Logger logger = loggerContext.getLogger(loggerName);
	logger.setLevel(Level.DEBUG);
}
 
Example 19
Source Project: cubeai   File: LogsResourceIntTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testLogstashAppender() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    assertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.class);
}
 
Example 20
Source Project: cubeai   File: LogsResourceIntTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testLogstashAppender() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    assertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.class);
}