Java Code Examples for org.apache.logging.log4j.Level#INFO

The following examples show how to use org.apache.logging.log4j.Level#INFO . 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: Log4J2Logger.java    From getty with Apache License 2.0 6 votes vote down vote up
private static Level toLevel(InternalLogLevel level) {
    switch (level) {
        case INFO:
            return Level.INFO;
        case DEBUG:
            return Level.DEBUG;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        case TRACE:
            return Level.TRACE;
        default:
            throw new Error();
    }
}
 
Example 2
Source File: Log4j2LoggerSpaceFactory.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
private Level toLog4j2Level(AdapterLevel adapterLevel) {
    if (adapterLevel == null) {
        throw new IllegalStateException("AdapterLevel is NULL when adapter to log4j2.");
    }
    switch (adapterLevel) {
        case TRACE:
            return Level.TRACE;
        case DEBUG:
            return Level.DEBUG;
        case INFO:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalStateException(adapterLevel
                                            + " is unknown when adapter to log4j2.");
    }
}
 
Example 3
Source File: MyLogger.java    From Flashtool with GNU General Public License v3.0 6 votes vote down vote up
public static void setLevel(Level level) {
	LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	Configuration config = ctx.getConfiguration();
	LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); 
	loggerConfig.setLevel(level);
	ctx.updateLoggers();
		if (level == Level.ERROR) {
			logger.error("<- This level is successfully initialized");
		}
		if (level == Level.WARN) {
			logger.warn("<- This level is successfully initialized");
		}
		if (level == Level.DEBUG) {
			logger.debug("<- This level is successfully initialized");
		}
		if (level == Level.INFO) {
			logger.info("<- This level is successfully initialized");
		}
}
 
Example 4
Source File: Log4j2MetricsTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void noDuplicateLoggingCountWhenMultipleNonAdditiveLoggersShareConfig() {
    LoggerContext loggerContext = new LoggerContext("test");

    LoggerConfig loggerConfig = new LoggerConfig("com.test", Level.INFO, false);
    Configuration configuration = loggerContext.getConfiguration();
    configuration.addLogger("com.test", loggerConfig);
    loggerContext.setConfiguration(configuration);
    loggerContext.updateLoggers();

    Logger logger1 = loggerContext.getLogger("com.test.log1");
    loggerContext.getLogger("com.test.log2");

    new Log4j2Metrics(emptyList(), loggerContext).bindTo(registry);

    assertThat(registry.get("log4j2.events").tags("level", "info").counter().count()).isEqualTo(0);
    logger1.info("Hello, world!");
    assertThat(registry.get("log4j2.events").tags("level", "info").counter().count()).isEqualTo(1);
}
 
Example 5
Source File: CliClient.java    From bt with Apache License 2.0 6 votes vote down vote up
private void configureLogging(LogLevel logLevel) {
    Level log4jLogLevel;
    switch (Objects.requireNonNull(logLevel)) {
        case NORMAL: {
            log4jLogLevel = Level.INFO;
            break;
        }
        case VERBOSE: {
            log4jLogLevel = Level.DEBUG;
            break;
        }
        case TRACE: {
            log4jLogLevel = Level.TRACE;
            break;
        }
        default: {
            throw new IllegalArgumentException("Unknown log level: " + logLevel.name());
        }
    }
    Configurator.setLevel("bt", log4jLogLevel);
}
 
Example 6
Source File: LogUtil.java    From raml-module-builder with Apache License 2.0 6 votes vote down vote up
private static Level getLog4jLevel(String level){
  if(level.equalsIgnoreCase("SEVERE")){
    return Level.ERROR;
  }
  else if(level.equalsIgnoreCase("WARNING")){
    return Level.WARN;
  }
  else if(level.equalsIgnoreCase("INFO")){
    return Level.INFO;
  }
  else if(level.equalsIgnoreCase("FINE")){
    return Level.DEBUG;
  }
  else if(level.equalsIgnoreCase("FINER") || level.equalsIgnoreCase("FINEST")){
    return Level.TRACE;
  }
  return Level.INFO;
}
 
Example 7
Source File: DefaultLogger.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
public static Level __parseLogLevel(LogLevel level) {
    switch (level.getLevel()) {
        case 600:
            return Level.TRACE;
        case 500:
            return Level.DEBUG;
        case 400:
            return Level.INFO;
        case 300:
            return Level.WARN;
        case 200:
            return Level.ERROR;
        case 100:
            return Level.FATAL;
        case 0:
            return Level.OFF;
        default:
            return Level.ALL;
    }
}
 
Example 8
Source File: ESLoggerConfigFactory.java    From core-ng-project with Apache License 2.0 6 votes vote down vote up
public static void configureLogger() {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();

    Map<String, ESLogger> loggers = Maps.newConcurrentHashMap();
    Appender appender = new AbstractAppender("", null, null) {
        @Override
        public void append(LogEvent event) {
            String name = event.getLoggerName();
            ESLogger logger = loggers.computeIfAbsent(name, key -> new ESLogger(key, null, (LoggerImpl) LoggerFactory.getLogger(key)));
            logger.log(event.getLevel(), event.getMarker(), event.getMessage(), event.getThrown());
        }
    };
    appender.start();
    config.addAppender(appender);

    var loggerConfig = new LoggerConfig("", Level.INFO, false); // only enable info and higher level
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("", loggerConfig);
    context.updateLoggers();
}
 
Example 9
Source File: AllureLogAppenderTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void shouldAddLogStepIfAllureStoryReporterIsSet()
{
    AllureLogAppender appender = AllureLogAppender.createAppender(NAME, filter, layout);
    final AllureStoryReporter allureStoryReporter = mock(AllureStoryReporter.class);
    appender.setAllureStoryReporter(allureStoryReporter);
    LogEvent logEvent = mock(LogEvent.class);
    final String logEntry = "message";
    final Level logLevel = Level.INFO;
    when(layout.toByteArray(logEvent)).thenReturn(logEntry.getBytes(StandardCharsets.UTF_8));
    when(logEvent.getLevel()).thenReturn(logLevel);
    appender.append(logEvent);
    verify(allureStoryReporter).addLogStep(logLevel.name(), logEntry);
}
 
Example 10
Source File: Log4J2Logger.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setLevel(@Nonnull LoggerLevel level) throws IllegalAccessException {
  Class callerClass = ReflectionUtil.findCallerClass(1);
  if (callerClass == null) {
    throw new IllegalAccessException("There not caller class");
  }

  PluginDescriptor plugin = PluginManager.getPlugin(callerClass);
  if (plugin == null || !PluginIds.isPlatformPlugin(plugin.getPluginId())) {
    throw new IllegalAccessException("Plugin is not platform: " + plugin);
  }

  org.apache.logging.log4j.core.Logger logger = myLoggerContext.getLogger(myLogger.getName());

  Level newLevel;
  switch (level) {

    case INFO:
      newLevel = Level.INFO;
      break;
    case WARNING:
      newLevel = Level.WARN;
      break;
    case ERROR:
      newLevel = Level.ERROR;
      break;
    case DEBUG:
      newLevel = Level.DEBUG;
      break;
    case TRACE:
      newLevel = Level.TRACE;
      break;
    default:
      throw new IllegalArgumentException("Wrong level: " + level);
  }

  logger.setLevel(newLevel);
}
 
Example 11
Source File: DiscardingAsyncQueueFullPolicyTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDiscardCount() throws Exception {
    final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.INFO);
    assertEquals("initially", 0, DiscardingAsyncQueueFullPolicy.getDiscardCount(router));

    assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO));
    assertEquals("increase", 1, DiscardingAsyncQueueFullPolicy.getDiscardCount(router));

    assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO));
    assertEquals("increase", 2, DiscardingAsyncQueueFullPolicy.getDiscardCount(router));

    assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO));
    assertEquals("increase", 3, DiscardingAsyncQueueFullPolicy.getDiscardCount(router));
}
 
Example 12
Source File: JoinHelper.java    From crate with Apache License 2.0 5 votes vote down vote up
static Level getLogLevel(TransportException e) {
    Throwable cause = e.unwrapCause();
    if (cause instanceof CoordinationStateRejectedException ||
        cause instanceof FailedToCommitClusterStateException ||
        cause instanceof NotMasterException) {
        return Level.DEBUG;
    }
    return Level.INFO;
}
 
Example 13
Source File: Log4jLogEventBenchmark.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Serializable createSerializableLogEventProxyWithoutExceptionWithLocation(final Blackhole bh) {
    final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, null, null);
    final Serializable obj = Log4jLogEvent.serialize(event, true);
    bh.consume(obj);
    return obj;
}
 
Example 14
Source File: MixinConfig.java    From Mixin with MIT License 4 votes vote down vote up
/**
 * Get the logging level for this config
 */
public Level getLoggingLevel() {
    return this.verboseLogging ? Level.INFO : Level.DEBUG;
}
 
Example 15
Source File: LoggerConfigBenchmark.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private static LogEvent createLogEventWithoutException() {
    return new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, new SimpleMessage("abc"), null, null);
}
 
Example 16
Source File: MixinEnvironment.java    From Mixin with MIT License 4 votes vote down vote up
/**
 * Get logging level info/debug based on verbose setting
 */
private Level getVerboseLoggingLevel() {
    return this.getOption(Option.DEBUG_VERBOSE) ? Level.INFO : Level.DEBUG;
}
 
Example 17
Source File: LevelTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testLevelLogging() {
    final Marker marker = MarkerManager.getMarker("marker");
    final Message msg = new ObjectMessage("msg");
    final Throwable t = new Throwable("test");
    final Level[] levels = new Level[] { Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL };
    final String[] names = new String[] { "levelTest", "levelTest.Trace", "levelTest.Debug", "levelTest.Info",
            "levelTest.Warn", "levelTest.Error", "levelTest.Fatal" };
    for (final Level level : levels) {
        for (final String name : names) {
            final Logger logger = context.getLogger(name);
            logger.log(level, msg); // Message
            logger.log(level, 123); // Object
            logger.log(level, name); // String
            logger.log(level, marker, msg); // Marker, Message
            logger.log(level, marker, 123); // Marker, Object
            logger.log(level, marker, name); // marker, String
            logger.log(level, msg, t); // Message, Throwable
            logger.log(level, 123, t); // Object, Throwable
            logger.log(level, name, "param1", "param2"); // String, Object...
            logger.log(level, name, t); // String, Throwable
            logger.log(level, marker, msg, t); // Marker, Message, Throwable
            logger.log(level, marker, 123, t); // Marker, Object, Throwable
            logger.log(level, marker, name, "param1", "param2"); // Marker, String, Object...
            logger.log(level, marker, name, t); // Marker, String, Throwable
        }
    }
    // Logger "levelTest" will not receive same events as "levelTest.Trace"
    int levelCount = names.length - 1;

    final int UNIT = 14;
    final Expected[] expectedResults = new Expected[] { //
    new Expected(listAll, UNIT * levelCount, "TRACE", "All"), //
            new Expected(listTrace, UNIT * levelCount--, "TRACE", "Trace"), //
            new Expected(listDebug, UNIT * levelCount--, "DEBUG", "Debug"), //
            new Expected(listInfo, UNIT * levelCount--, "INFO", "Info"), //
            new Expected(listWarn, UNIT * levelCount--, "WARN", "Warn"), //
            new Expected(listError, UNIT * levelCount--, "ERROR", "Error"), //
            new Expected(listFatal, UNIT * levelCount--, "FATAL", "Fatal"), //
    };
    for (final Expected expected : expectedResults) {
        final String description = expected.description;
        final List<LogEvent> events = expected.appender.getEvents();
        assertNotNull(description + ": No events", events);
        assertThat(events, hasSize(expected.expectedEventCount));
        final LogEvent event = events.get(0);
        assertEquals(
            description + ": Expected level " + expected.expectedInitialEventLevel + ", got" + event.getLevel(),
            event.getLevel().name(), expected.expectedInitialEventLevel);
    }
}
 
Example 18
Source File: AppenderControlArraySetTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private AppenderControl createControl(final String name) {
    final Appender appender = FailOnceAppender.createAppender(name);
    return new AppenderControl(appender, Level.INFO, null);
}
 
Example 19
Source File: Log4jLogEventBenchmark.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Benchmark
public LogEvent createLogEventWithoutException() {
    return new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, null, null);
}
 
Example 20
Source File: InfoTag.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected Level getLevel() {
    return Level.INFO;
}