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

The following examples show how to use org.apache.logging.log4j.Level#TRACE . 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: SLF4JLogger.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public Level getLevel() {
    if (logger.isTraceEnabled()) {
        return Level.TRACE;
    }
    if (logger.isDebugEnabled()) {
        return Level.DEBUG;
    }
    if (logger.isInfoEnabled()) {
        return Level.INFO;
    }
    if (logger.isWarnEnabled()) {
        return Level.WARN;
    }
    if (logger.isErrorEnabled()) {
        return Level.ERROR;
    }
    // Option: throw new IllegalStateException("Unknown SLF4JLevel");
    // Option: return Level.ALL;
    return Level.OFF;
}
 
Example 3
Source File: LevelRangeFilterBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private Filter createFilter(String levelMax, String levelMin, boolean acceptOnMatch) {
    Level max = Level.FATAL;
    Level min = Level.TRACE;
    if (levelMax != null) {
        max = Level.toLevel(levelMax, Level.FATAL);
    }
    if (levelMin != null) {
        min = Level.toLevel(levelMin, Level.DEBUG);
    }
    org.apache.logging.log4j.core.Filter.Result onMatch = acceptOnMatch
            ? org.apache.logging.log4j.core.Filter.Result.ACCEPT
            : org.apache.logging.log4j.core.Filter.Result.NEUTRAL;

    return new FilterWrapper(LevelRangeFilter.createFilter(min, max, onMatch,
            org.apache.logging.log4j.core.Filter.Result.DENY));
}
 
Example 4
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 5
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 6
Source File: Log4J2Logger.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
protected 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 7
Source File: Log4J2Logger.java    From mynlp with Apache License 2.0 6 votes vote down vote up
protected 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 8
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 9
Source File: LogTypeConverter.java    From teku with Apache License 2.0 6 votes vote down vote up
@Override
public Level convert(String value) {
  switch (value.toUpperCase()) {
    case "OFF":
      return Level.OFF;
    case "FATAL":
      return Level.FATAL;
    case "WARN":
      return Level.WARN;
    case "INFO":
      return Level.INFO;
    case "DEBUG":
      return Level.DEBUG;
    case "TRACE":
      return Level.TRACE;
    case "ALL":
      return Level.ALL;
  }
  throw (new CommandLine.TypeConversionException(
      "'"
          + value
          + "' is not a valid log level. Supported values are [OFF|FATAL|WARN|INFO|DEBUG|TRACE|ALL]"));
}
 
Example 10
Source File: LoggingMixin.java    From picocli with Apache License 2.0 5 votes vote down vote up
private Level calcLogLevel() {
    switch (getVerbosity().length) {
        case 0:  return Level.WARN;
        case 1:  return Level.INFO;
        case 2:  return Level.DEBUG;
        default: return Level.TRACE;
    }
}
 
Example 11
Source File: MyApp.java    From picocli with Apache License 2.0 5 votes vote down vote up
private Level calcLogLevel() {
    switch (loggingMixin.verbosity.length) {
        case 0:  return Level.WARN;
        case 1:  return Level.INFO;
        case 2:  return Level.DEBUG;
        default: return Level.TRACE;
    }
}
 
Example 12
Source File: DiscardingAsyncQueueFullPolicyTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRouteDiscardsIfQueueFullAndLevelEqualOrLessSpecificThanThreshold() throws Exception {
    final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN);

    for (final Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) {
        assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level));
        assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level));
    }
}
 
Example 13
Source File: LoggingMixin.java    From picocli with Apache License 2.0 5 votes vote down vote up
private Level calcLogLevel() {
    switch (getVerbosity().length) {
        case 0:  return Level.WARN;
        case 1:  return Level.INFO;
        case 2:  return Level.DEBUG;
        default: return Level.TRACE;
    }
}
 
Example 14
Source File: Main.java    From ict with Apache License 2.0 5 votes vote down vote up
public void enableTrace() {
    if (disableRootLevelSetting) {
        return;
    }
    rootLevel = Level.TRACE;
    Configurator.setRootLevel(Level.TRACE);
}
 
Example 15
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationDeserialization() throws IOException, ClassNotFoundException {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = "logger.name";
    final Marker marker = null;
    final String fqcn = "f.q.c.n";
    final Level level = Level.TRACE;
    final Message data = new SimpleMessage("message");
    final Throwable t = new InternalError("not a real error");
    final ContextStack contextStack = null;
    final String threadName = "main";
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location,
            new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
    ((StringMap) evt.getContextData()).putValue("key", "value");

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(evt);

    final ObjectInputStream in = new FilteredObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    final RingBufferLogEvent other = (RingBufferLogEvent) in.readObject();
    assertEquals(loggerName, other.getLoggerName());
    assertEquals(marker, other.getMarker());
    assertEquals(fqcn, other.getLoggerFqcn());
    assertEquals(level, other.getLevel());
    assertEquals(data, other.getMessage());
    assertNull("null after serialization", other.getThrown());
    assertEquals(new ThrowableProxy(t), other.getThrownProxy());
    assertEquals(evt.getContextData(), other.getContextData());
    assertEquals(contextStack, other.getContextStack());
    assertEquals(threadName, other.getThreadName());
    assertEquals(location, other.getSource());
    assertEquals(12345, other.getTimeMillis());
    assertEquals(678, other.getInstant().getNanoOfMillisecond());
}
 
Example 16
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateMementoRetainsParametersAndFormat() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    // Initialize the event with parameters
    evt.swapParameters(new Object[10]);
    final String loggerName = "logger.name";
    final Marker marker = MarkerManager.getMarker("marked man");
    final String fqcn = "f.q.c.n";
    final Level level = Level.TRACE;
    ReusableMessageFactory factory = new ReusableMessageFactory();
    Message message = factory.newMessage("Hello {}!", "World");
    try {
        final Throwable t = new InternalError("not a real error");
        final ContextStack contextStack = new MutableThreadContextStack(Arrays.asList("a", "b"));
        final String threadName = "main";
        final StackTraceElement location = null;
        evt.setValues(null, loggerName, marker, fqcn, level, message, t, (StringMap) evt.getContextData(),
                contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
        ((StringMap) evt.getContextData()).putValue("key", "value");

        final Message actual = evt.createMemento().getMessage();
        assertEquals("Hello {}!", actual.getFormat());
        assertArrayEquals(new String[]{"World"}, actual.getParameters());
        assertEquals("Hello World!", actual.getFormattedMessage());
    } finally {
        ReusableMessageFactory.release(message);
    }
}
 
Example 17
Source File: Log4jLogger.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private static Level getLevel(final int i) {
    switch (i) {
    case TRACE_INT:
        return Level.TRACE;
    case DEBUG_INT:
        return Level.DEBUG;
    case INFO_INT:
        return Level.INFO;
    case WARN_INT:
        return Level.WARN;
    case ERROR_INT:
        return Level.ERROR;
    }
    return Level.ERROR;
}
 
Example 18
Source File: RollingAppenderDirectWrite1906Test.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Level getStatusLevel() {
    return Level.TRACE;
}
 
Example 19
Source File: TraceTag.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
protected Level getLevel() {
    return Level.TRACE;
}
 
Example 20
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);
    }
}