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

The following examples show how to use org.slf4j.LoggerFactory#getILoggerFactory() . 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: ApplicationInfomationController.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
@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 File: LogsResource.java    From cubeai with 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 File: LogUtil.java    From chaosblade-exec-jvm with 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
Source File: XodusFileDataWriterLogLevelModificatorTest.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@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 File: MQAdminStartup.java    From rocketmq-read with 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
Source File: XodusFileDataWriterLogLevelModificatorSingularityTest.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@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 File: LogsResource.java    From cubeai with 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 File: LogsResource.java    From cubeai with 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 File: LogsResource.java    From flair-engine with 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 File: LogsResource.java    From cubeai with 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 11
Source File: LogUtils.java    From konduit-serving with 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 12
Source File: MQAdminStartup.java    From rocketmq-4.3.0 with 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 13
Source File: LogbackTest.java    From rocketmq-4.3.0 with 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 14
Source File: DiagnosticLogging.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
Source File: LogsResourceIntTest.java    From cubeai with 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
Source File: LogsResourceIntTest.java    From cubeai with 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 17
Source File: Rsc.java    From rsc with 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 18
Source File: LogsResourceIntTest.java    From cubeai with 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 19
Source File: Slf4jLoggerFactory.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public Slf4jLoggerFactory() {
    LoggerFactory.getILoggerFactory();
    doRegister();
}
 
Example 20
Source File: LogsResourceIntTest.java    From cubeai with 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);
}