Java Code Examples for ch.qos.logback.classic.Level#WARN

The following examples show how to use ch.qos.logback.classic.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: LogLevelConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 2
Source File: LogLevelConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 3
Source File: BaleenLoggerBuilderTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testFileWithoutDailyRolling() {
  BaleenFileLoggerBuilder builder =
      new BaleenFileLoggerBuilder(
          NAME,
          BaleenLogging.DEFAULT_PATTERN,
          LOG_FILENAME,
          new MinMaxFilter(Level.INFO, Level.WARN),
          false,
          Optional.of(5),
          Optional.of(10));

  LoggerContext context = new LoggerContext();
  Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();

  Appender<ILoggingEvent> appender = builder.build(context, encoder);

  assertTrue(appender instanceof FileAppender);
  assertEquals(encoder, ((FileAppender<ILoggingEvent>) appender).getEncoder());

  // TODO: Add tests on the (current private) methods
}
 
Example 4
Source File: LogbackLoggerSpaceFactory.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
private Level toLogbackLevel(AdapterLevel adapterLevel) {
    if (adapterLevel == null) {
        throw new IllegalStateException("AdapterLevel is NULL when adapter to logback.");
    }
    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 logback.");
    }
}
 
Example 5
Source File: LogLevelConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 6
Source File: LoggingRule.java    From datakernel with Apache License 2.0 6 votes vote down vote up
private Level getAdaptedLevel(org.slf4j.event.Level level) {
	switch (level) {
		case ERROR:
			return Level.ERROR;
		case WARN:
			return Level.WARN;
		case INFO:
			return Level.INFO;
		case DEBUG:
			return Level.DEBUG;
		case TRACE:
			return Level.TRACE;
		default:
			return DEFAULT_LOGGING_LEVEL;
	}
}
 
Example 7
Source File: CommandLineClient.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
private void applyLogConfig() {
	boolean loggingActivated = isSet(TermSuiteCliOption.LOG_INFO) 
			|| isSet(TermSuiteCliOption.LOG_DEBUG) 
			|| isSet(TermSuiteCliOption.LOG_TO_FILE);
	
	if(loggingActivated) {
		OutputStreamAppender<ILoggingEvent> appender = 
				isSet(TermSuiteCliOption.LOG_TO_FILE) ?
						LogbackUtils.createFileAppender(asPath(TermSuiteCliOption.LOG_TO_FILE)) :
							LogbackUtils.createConsoleAppender();
		LogbackUtils.activateLogging(appender);
		
		Level level = Level.WARN;
		if(isSet(TermSuiteCliOption.LOG_INFO))
			level = Level.INFO;
		else if(isSet(TermSuiteCliOption.LOG_DEBUG))
			level = Level.DEBUG;
		else if(isSet(TermSuiteCliOption.LOG_TO_FILE))
			level = Level.INFO;
		LogbackUtils.setGlobalLogLevel(level);
	}
}
 
Example 8
Source File: BaleenLoggerBuilderTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testFileWithDailyRolling() {
  BaleenFileLoggerBuilder builder =
      new BaleenFileLoggerBuilder(
          NAME,
          BaleenLogging.DEFAULT_PATTERN,
          LOG_FILENAME,
          new MinMaxFilter(Level.INFO, Level.WARN),
          true,
          Optional.of(5),
          Optional.of(10));

  LoggerContext context = new LoggerContext();
  Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();

  Appender<ILoggingEvent> appender = builder.build(context, encoder);

  assertTrue(appender instanceof FileAppender);
  assertEquals(encoder, ((FileAppender<ILoggingEvent>) appender).getEncoder());

  // TODO: Add tests on the (current private) methods
}
 
Example 9
Source File: BaleenLoggerBuilderTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
/** Test abstract functions (using console implementation) and the functions of console */
@Test
public void testAbstractAndConsole() {
  BaleenConsoleLoggerBuilder builder =
      new BaleenConsoleLoggerBuilder(
          NAME, BaleenLogging.DEFAULT_PATTERN, new MinMaxFilter(Level.INFO, Level.WARN));

  LoggerContext context = new LoggerContext();
  Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();

  Appender<ILoggingEvent> appender = builder.build(context, encoder);

  assertEquals(NAME, builder.getName());

  assertTrue(appender instanceof ConsoleAppender);
  assertEquals(encoder, ((ConsoleAppender<ILoggingEvent>) appender).getEncoder());

  assertNotNull(appender);
  assertEquals(NAME, appender.getName());
  Filter<ILoggingEvent> filter = appender.getCopyOfAttachedFiltersList().get(0);
  assertTrue(filter instanceof MinMaxFilter);
  assertEquals(Level.INFO, ((MinMaxFilter) filter).getMin());
  assertEquals(Level.WARN, ((MinMaxFilter) filter).getMax());
}
 
Example 10
Source File: LogLevelConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 11
Source File: LogUtil.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Level toLevel (final String str)
{
    switch (str.toUpperCase()) {
    case "ALL":
        return Level.ALL;

    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:
    case "OFF":
        return Level.OFF;
    }
}
 
Example 12
Source File: LoggerOutputStream.java    From NationStatesPlusPlus with MIT License 6 votes vote down vote up
@Override
public synchronized void flush() throws IOException {
	super.flush();
	String record = this.toString();
	super.reset();

	if (record.length() > 0 && !record.equals(separator) && level != Level.OFF) {
		if (level == Level.TRACE)
			log.trace(record);
		else if (level == Level.DEBUG)
			log.debug(record);
		else if (level == Level.INFO)
			log.info(record);
		else if (level == Level.WARN)
			log.warn(record);
		else if (level == Level.ERROR)
			log.error(record);
	}
}
 
Example 13
Source File: SLF4JLoggerIT.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
/**
 * Converts log levels in {@link LogLevel} to appropriate levels in
 * {@link Level}.
 */
private Level toLogBackLevel(LogLevel level)
{
  switch (level)
  {
    case ERROR:
      return Level.ERROR;
    case WARNING:
      return Level.WARN;
    case INFO:
      return Level.INFO;
    case DEBUG:
      return Level.DEBUG;
    case TRACE:
      return Level.TRACE;
  }

  return Level.TRACE;
}
 
Example 14
Source File: LogbackLoggingConfigurer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
    Level loggerLevel = logger.getEffectiveLevel();
    if (loggerLevel == Level.INFO && (level == Level.INFO || level == Level.WARN)
            || level == Level.INFO && (loggerLevel == Level.INFO || loggerLevel == Level.WARN)) {
        // Need to take into account Gradle's LIFECYCLE and QUIET markers. Whether those are set can only be determined
        // for the global log level, but not for the logger's log level (at least not without walking the logger's
        // hierarchy, which is something that Logback is designed to avoid for performance reasons).
        // Hence we base our decision on the global log level.
        LogLevel eventLevel = LogLevelConverter.toGradleLogLevel(level, marker);
        return eventLevel.compareTo(currentLevel) >= 0 ? FilterReply.ACCEPT : FilterReply.DENY;
    }

    return level.isGreaterOrEqual(loggerLevel) ? FilterReply.ACCEPT : FilterReply.DENY;
}
 
Example 15
Source File: LoggingUtil.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private Level toLevel(LogLevel logLevel) {
    switch (logLevel) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        default:
            return Level.ERROR;
    }
}
 
Example 16
Source File: LoggingUtils.java    From heat with Apache License 2.0 5 votes vote down vote up
/**
 * This method sets the log level (logback).
 */
public void setLogLevel() {
    logLevel = System.getProperty("logLevel", LOG_LEVEL_INFO);
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    Level logLevelSetting;
    switch (logLevel.toLowerCase()) {
    case LOG_LEVEL_ERROR:
        logLevelSetting = Level.ERROR;
        break;
    case LOG_LEVEL_WARN:
        logLevelSetting = Level.WARN;
        break;
    case LOG_LEVEL_ALL:
        logLevelSetting = Level.ALL;
        break;
    case LOG_LEVEL_TRACE_LOG:
        logLevelSetting = Level.TRACE;
        break;
    case LOG_LEVEL_INFO:
        logLevelSetting = Level.INFO;
        break;
    case LOG_LEVEL_DEBUG:
        logLevelSetting = Level.DEBUG;
        break;
    default:
        logLevelSetting = Level.INFO;
        break;
    }
    root.setLevel(logLevelSetting);
}
 
Example 17
Source File: ErrorCatcher.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    String msg = event.getFormattedMessage();
    if (msg == null)
        msg = "null";
    if (event.getMarker() != Markers.NO_ANNOUNCE
            && FlareBot.instance() != null
            && event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        String finalMsg = msg;
        if (event.getThreadName().startsWith("lava-daemon-pool")) {
            return FilterReply.NEUTRAL;
        }
        EXECUTOR.submit(() -> {
            Throwable throwable = null;
            if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
                throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
            }
            if (event.getLevel() == Level.WARN) {
                // Warnings should not have a throwable!
                MessageUtils.sendWarningMessage(finalMsg, Constants.getErrorLogChannel());
                return;
            }
            if (throwable != null) {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalException(finalMsg, throwable, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendException(finalMsg, throwable, Constants.getErrorLogChannel());
            } else {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalErrorMessage(finalMsg, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendErrorMessage(finalMsg, Constants.getErrorLogChannel());
            }
        });
    }
    return FilterReply.NEUTRAL;
}
 
Example 18
Source File: LogbackLogConfigurator.java    From butterfly with MIT License 5 votes vote down vote up
private Level getLogbackLogLevel(org.slf4j.event.Level slf4jLevel) {
    if(slf4jLevel.equals(org.slf4j.event.Level.INFO)) return Level.INFO;
    if(slf4jLevel.equals(org.slf4j.event.Level.DEBUG)) return Level.DEBUG;
    if(slf4jLevel.equals(org.slf4j.event.Level.WARN)) return Level.WARN;
    if(slf4jLevel.equals(org.slf4j.event.Level.ERROR)) return Level.ERROR;

    throw new IllegalArgumentException("Unknown log level");
}
 
Example 19
Source File: LogbackLoggingConfigurer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
    Level loggerLevel = logger.getEffectiveLevel();
    if (loggerLevel == Level.INFO && (level == Level.INFO || level == Level.WARN)
            || level == Level.INFO && (loggerLevel == Level.INFO || loggerLevel == Level.WARN)) {
        // Need to take into account Gradle's LIFECYCLE and QUIET markers. Whether those are set can only be determined
        // for the global log level, but not for the logger's log level (at least not without walking the logger's
        // hierarchy, which is something that Logback is designed to avoid for performance reasons).
        // Hence we base our decision on the global log level.
        LogLevel eventLevel = LogLevelConverter.toGradleLogLevel(level, marker);
        return eventLevel.compareTo(currentLevel) >= 0 ? FilterReply.ACCEPT : FilterReply.DENY;
    }

    return level.isGreaterOrEqual(loggerLevel) ? FilterReply.ACCEPT : FilterReply.DENY;
}
 
Example 20
Source File: LogbackLoggingConfigurer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
    Level loggerLevel = logger.getEffectiveLevel();
    if (loggerLevel == Level.INFO && (level == Level.INFO || level == Level.WARN)
            || level == Level.INFO && (loggerLevel == Level.INFO || loggerLevel == Level.WARN)) {
        // Need to take into account Gradle's LIFECYCLE and QUIET markers. Whether those are set can only be determined
        // for the global log level, but not for the logger's log level (at least not without walking the logger's
        // hierarchy, which is something that Logback is designed to avoid for performance reasons).
        // Hence we base our decision on the global log level.
        LogLevel eventLevel = LogLevelConverter.toGradleLogLevel(level, marker);
        return eventLevel.compareTo(currentLevel) >= 0 ? FilterReply.ACCEPT : FilterReply.DENY;
    }

    return level.isGreaterOrEqual(loggerLevel) ? FilterReply.ACCEPT : FilterReply.DENY;
}