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

The following examples show how to use org.apache.logging.log4j.Level#WARN . 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: 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 3
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 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: 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 7
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 8
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 9
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 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: DiscardingAsyncQueueFullPolicyTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRouteSynchronousIfCurrentThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception {
    final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN);

    for (final Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
        assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level));
    }
}
 
Example 12
Source File: ModifyConstantInjector.java    From Mixin with MIT License 5 votes vote down vote up
private void checkNarrowing(Target target, AbstractInsnNode constNode, Type constantType, Type type, int index, String description) {
    int fromSort = constantType.getSort();
    int toSort = type.getSort();
    if (toSort < fromSort) {
        String fromType = SignaturePrinter.getTypeName(constantType, false);
        String toType = SignaturePrinter.getTypeName(type, false);
        String message = toSort == Type.BOOLEAN ? ". Implicit conversion to <boolean> can cause nondeterministic (JVM-specific) behaviour!" : "";
        Level level = toSort == Type.BOOLEAN ? Level.ERROR : Level.WARN;
        Injector.logger.log(level, "Narrowing conversion of <{}> to <{}> in {} target {} at opcode {} ({}){}", fromType, toType, this.info,
                target, index, description, message);
    }
}
 
Example 13
Source File: UtilsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test setting the global logging level for Picard, Log4j, MinLog and java.util.logging.
 *
 * Note that there are three very similar, but not identical, logging level enums from different namespaces
 * being used here. The one used by Picard (and Hellbender --verbosity) of type "Log.LogLevel", the parallel
 * one used by log4j of type "Level", and the one used by java.utils.logging.
 *
 */
@Test
public void testSetLoggingLevel() {
    // Query and cache the initial  Log4j level in place at the start of the tests so we can restore it at the
    // end of the tests. Also, since we're QUERYING the Log4j level, but we're SETTING the level using the
    // LoggingUtils API, we also need to verify here that the initial level is one of the narrower set of levels
    // that is supported by LoggingUtils, since those are the only ones we can restore through the LoggingUtils API.
    Level initialLevel = logger.getLevel();
    boolean goodInitialLevel =
            initialLevel == Level.DEBUG ||
            initialLevel == Level.WARN ||
            initialLevel == Level.ERROR ||
            initialLevel == Level.INFO;
    Assert.assertTrue(goodInitialLevel);

    // Set and test each supported logging level in turn
    LoggingUtils.setLoggingLevel(LogLevel.DEBUG);
    Assert.assertTrue(logger.getLevel() == Level.DEBUG);

    LoggingUtils.setLoggingLevel(LogLevel.WARNING);
    Assert.assertTrue(logger.getLevel() == Level.WARN);

    LoggingUtils.setLoggingLevel(LogLevel.ERROR);
    Assert.assertTrue(logger.getLevel() == Level.ERROR);

    LoggingUtils.setLoggingLevel(LogLevel.INFO);
    Assert.assertTrue(logger.getLevel() == Level.INFO);

    // Restore the logging level back to the original level in place at the beginning of the test
    LoggingUtils.setLoggingLevel(LoggingUtils.levelFromLog4jLevel(initialLevel));
    Assert.assertTrue(logger.getLevel() == initialLevel);
}
 
Example 14
Source File: TextAreaAppender.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
  * This method is where the appender does the work.
  *
  * @param event Log event with log data
  */
 @Override
 public void append(LogEvent event) {
   readLock.lock();
   String message = new String(getLayout().toByteArray(event));
   Level l = event.getLevel();
if (styledText!=null) {
	StyleRange styleRange = new StyleRange();
	if (l==Level.ERROR) {
		styleRange.length = message.length();
		styleRange.fontStyle = SWT.NORMAL;
		styleRange.foreground = cred;
		
	}
	else if (l==Level.WARN) {
		styleRange.length = message.length();
		styleRange.fontStyle = SWT.NORMAL;
		styleRange.foreground = cblue;
	}
	else {
		
		styleRange.length = message.length();
		styleRange.fontStyle = SWT.NORMAL;
		styleRange.foreground = cblack;
	}
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			// Append formatted message to textarea.
			styleRange.start = styledText.getCharCount();
			styledText.append(message);
			styledText.setStyleRange(styleRange);
			styledText.setSelection(styledText.getCharCount());
		}
	});
}
readLock.unlock();
 }
 
Example 15
Source File: DiscardingAsyncQueueFullPolicyTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRouteDiscardsIfThresholdCapacityReachedAndLevelEqualOrLessSpecificThanThreshold()
        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));
        assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level));
        assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level));
    }
}
 
Example 16
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 17
Source File: DiscardingAsyncQueueFullPolicyTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRouteEnqueueIfOtherThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception {
    final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN);

    for (final Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
        assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level));
    }
}
 
Example 18
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 19
Source File: Log4j2LoggingHelper.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a generic log level to a Log4J specific log level.
 *
 * @param logLevel the generic log level.
 *
 * @return the Log4J specific log level.
 */
private Level genericLogLevelToLog4j(LogLevel logLevel)
{
    Level level = Level.ALL;
    if (logLevel.equals(LogLevel.OFF))
    {
        level = Level.OFF;
    }
    else if (logLevel.equals(LogLevel.FATAL))
    {
        level = Level.FATAL;
    }
    else if (logLevel.equals(LogLevel.ERROR))
    {
        level = Level.ERROR;
    }
    else if (logLevel.equals(LogLevel.WARN))
    {
        level = Level.WARN;
    }
    else if (logLevel.equals(LogLevel.INFO))
    {
        level = Level.INFO;
    }
    else if (logLevel.equals(LogLevel.DEBUG))
    {
        level = Level.DEBUG;
    }
    else if (logLevel.equals(LogLevel.TRACE))
    {
        level = Level.TRACE;
    }
    else if (logLevel.equals(LogLevel.ALL))
    {
        level = Level.ALL;
    }
    else
    {
        LOGGER.warn("Unsupported log level encountered: " + logLevel.toString() + ". Using ALL.");
    }
    return level;
}
 
Example 20
Source File: ValidatingPluginWithFailoverTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Level getStatusLevel() {
    return Level.WARN;
}