Java Code Examples for ch.qos.logback.classic.Logger#getLevel()

The following examples show how to use ch.qos.logback.classic.Logger#getLevel() . 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: LogbackHelper.java    From arthas with Apache License 2.0 6 votes vote down vote up
private static Map<String, Object> doGetLoggerInfo(Logger logger) {
    Map<String, Object> info = new LinkedHashMap<String, Object>();
    info.put(LoggerHelper.name, logger.getName());
    info.put(LoggerHelper.clazz, logger.getClass());
    CodeSource codeSource = logger.getClass().getProtectionDomain().getCodeSource();
    if (codeSource != null) {
        info.put(LoggerHelper.codeSource, codeSource.getLocation());
    }
    info.put(LoggerHelper.additivity, logger.isAdditive());

    Level level = logger.getLevel(), effectiveLevel = logger.getEffectiveLevel();
    if (level != null) {
        info.put(LoggerHelper.level, level.toString());
    }
    if (effectiveLevel != null) {
        info.put(LoggerHelper.effectiveLevel, effectiveLevel.toString());
    }

    List<Map<String, Object>> result = doGetLoggerAppenders(logger.iteratorForAppenders());
    info.put(LoggerHelper.appenders, result);
    return info;
}
 
Example 2
Source File: LogbackRootLoggerCheckerTest.java    From micro-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheck() {
	checker.check();
	 Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
	 Level actualLevel = root.getLevel();
	assertThat(actualLevel, is(Level.INFO));
	
	checker.setCorrectLevelStr("DEBUG");
	checker.check();
	actualLevel = root.getLevel();
	assertThat(actualLevel, is(Level.DEBUG));
	
	checker.setActive(false);
	checker.setCorrectLevelStr("WARN");
	checker.check();
	actualLevel = root.getLevel();
	assertThat(actualLevel, is(Level.DEBUG));
}
 
Example 3
Source File: VersionTranslatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Test( timeout = 2000 )
public void testTranslateVersionsPerformance() throws RestException
{
    Logger logbackLogger = ( (Logger) LoggerFactory.getLogger( Logger.ROOT_LOGGER_NAME ) );
    Level originalLevel = logbackLogger.getLevel();

    try
    {
        // Disable logging for this test as impacts timing.
        logbackLogger.setLevel( Level.OFF );
        versionTranslator.translateVersions( aLotOfGavs );
    }
    finally
    {
        logbackLogger.setLevel( originalLevel );
    }
}
 
Example 4
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 5
Source File: CBDriver.java    From jdbc-cb with Apache License 2.0 5 votes vote down vote up
public static Level getLogLevel()
{
    synchronized (CBDriver.class)
    {
        Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.couchbase");
        return logger.getLevel();
    }
}
 
Example 6
Source File: TracerTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Test
public void make_code_coverage_happy2() {
    Logger tracerValidSpanLogger = (Logger) Whitebox.getInternalState(Tracer.getInstance(), "validSpanLogger");
    Level origLevel = tracerValidSpanLogger.getLevel();
    try {
        // Disable info logging.
        tracerValidSpanLogger.setLevel(Level.WARN);
        // Exercise the span completion logic to trigger the do-nothing branch when info logging is disabled.
        Tracer.getInstance().startRequestWithRootSpan("foo");
        Tracer.getInstance().completeRequestSpan();
    }
    finally {
        tracerValidSpanLogger.setLevel(origLevel);
    }
}
 
Example 7
Source File: TracerTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Test
public void make_code_coverage_happy3() {
    Logger tracerClassLogger = (Logger) Whitebox.getInternalState(Tracer.getInstance(), "classLogger");
    Level origLevel = tracerClassLogger.getLevel();
    try {
        // Enable debug logging.
        tracerClassLogger.setLevel(Level.DEBUG);
        // Exercise a span lifecycle to trigger the code branches that only do something if debug logging is on.
        Tracer.getInstance().startRequestWithRootSpan("foo");
        Tracer.getInstance().completeRequestSpan();
    }
    finally {
        tracerClassLogger.setLevel(origLevel);
    }
}
 
Example 8
Source File: LogControlImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getLoggers() {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    List<String> list = new ArrayList<>();
    for (Logger log : lc.getLoggerList()) {
        if (log.getLevel() != null || hasAppenders(log)) {
            list.add(log.getName());
        }
    }
    return list;
}
 
Example 9
Source File: OffHeapHashMapTableResizeIT.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Test
public void testLargeTableResizes() {
  Logger logger = (Logger)LoggerFactory.getLogger(OffHeapHashMap.class);
  Level oldLevel = logger.getLevel();
  logger.setLevel(Level.ALL);
  try {
    Map<Integer, Integer> map = new OffHeapHashMap<>(new UpfrontAllocatingPageSource(new OffHeapBufferSource(), 32 * 1024 * 1024, 32 * 1024 * 1024), new SplitStorageEngine<>(new IntegerStorageEngine(), new IntegerStorageEngine()), 1);

    for (int i = 0; i < 500000; i++) {
      map.put(i, i);
    }
  } finally {
    logger.setLevel(oldLevel);
  }
}
 
Example 10
Source File: LogbackRootLoggerChecker.java    From micro-server with Apache License 2.0 5 votes vote down vote up
@Scheduled(fixedRateString = "${logback.root.logger.checker.fixed.rate:5000}")
public void check() {
	if (active) {
	
		 Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
		 Level actualLevel = root.getLevel();
		if (!actualLevel.toString().equals(correctLevelStr)) {
			root.setLevel(Level.toLevel(correctLevelStr));
			logger.warn("Logback log level {} was incorrect. Changed to {}", actualLevel.toString(), correctLevelStr);
		}
	}
}
 
Example 11
Source File: LoggerService.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets a logger, if checkLevel is true and if logger has no level defined it will return a
 * NameNotFound exception
 */
protected Logger getLogger(String name, boolean checkLevel) throws NotFoundException {
  LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

  Logger log = loggerContext.getLogger(name);
  if (checkLevel && log.getLevel() == null) {
    throw new NotFoundException("The logger with name " + name + " is not existing.");
  }
  return log;
}
 
Example 12
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
private static Level disableLogging() {
	LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	Logger logger = logContext.getLogger(SimpleMessageListenerContainer.class);
	Level previous = logger.getLevel();
	logger.setLevel(Level.OFF);
	return previous;
}
 
Example 13
Source File: LogLevel.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public String get() {
	Logger logbackRootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
	Level currentLevel = logbackRootLogger.getLevel();
	return LOG_LEVELS.inverse().getOrDefault(currentLevel, currentLevel.levelStr);
}
 
Example 14
Source File: AbstractWorkflowIT.java    From telekom-workflow-engine with MIT License 4 votes vote down vote up
@BeforeClass
public static void beforeClass(){
    Logger log = (Logger)LoggerFactory.getLogger( WorkflowExecutorImpl.class );
    executorLogLevel = log.getLevel();
    log.setLevel( Level.ERROR );
}
 
Example 15
Source File: LoggingBootstrapTest.java    From hivemq-community-edition with Apache License 2.0 3 votes vote down vote up
@Before
public void setUp() throws Exception {
    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    level = logger.getLevel();

    logger.setLevel(Level.INFO);

}