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

The following examples show how to use ch.qos.logback.classic.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: 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: 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 3
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 4
Source File: BaleenLoggerBuilderTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testFileWithDailyRollingWithoutSize() {
  BaleenFileLoggerBuilder builder =
      new BaleenFileLoggerBuilder(
          NAME,
          BaleenLogging.DEFAULT_PATTERN,
          LOG_FILENAME,
          new MinMaxFilter(Level.INFO, Level.WARN),
          true,
          Optional.empty(),
          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 5
Source File: LoggerNameAndLevelFilterTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecideForNullLoggerName() throws Exception
{
    LoggerNameAndLevelFilter filter = new LoggerNameAndLevelFilter(null, Level.INFO);

    ILoggingEvent event = mock(ILoggingEvent.class);
    when(event.getLevel()).thenReturn(Level.INFO);
    when(event.getLoggerName()).thenReturn("org.apache.qpid.server.foo");
    assertEquals("Unexpected reply for matching log level and arbitrary logger name",
                        FilterReply.ACCEPT,
                        filter.decide(event));

    when(event.getLoggerName()).thenReturn("org.apache.qpid.foo");
    assertEquals("Unexpected reply for matching log level and arbitrary logger name",
                        FilterReply.ACCEPT,
                        filter.decide(event));

    when(event.getLevel()).thenReturn(Level.DEBUG);
    assertEquals("Unexpected reply for non matching log level", FilterReply.NEUTRAL, filter.decide(event));
}
 
Example 6
Source File: LoggerNameAndLevelFilterTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecideForWildcardLoggerName() throws Exception
{
    LoggerNameAndLevelFilter filter = new LoggerNameAndLevelFilter("org.apache.qpid.server.*", Level.INFO);

    ILoggingEvent event = mock(ILoggingEvent.class);
    when(event.getLevel()).thenReturn(Level.INFO);
    when(event.getLoggerName()).thenReturn("org.apache.qpid.server.foo");
    assertEquals("Unexpected reply for matching logger name and log level",
                        FilterReply.ACCEPT,
                        filter.decide(event));

    when(event.getLoggerName()).thenReturn("org.apache.qpid.foo");
    assertEquals("Unexpected reply for non matching logger name but matching log level",
                        FilterReply.NEUTRAL,
                        filter.decide(event));

    when(event.getLoggerName()).thenReturn("org.apache.qpid.server.foo");
    when(event.getLevel()).thenReturn(Level.DEBUG);
    assertEquals("Unexpected reply for matching logger name but non matching log level",
                        FilterReply.NEUTRAL,
                        filter.decide(event));
}
 
Example 7
Source File: SelfCheckHttpServer.java    From krpc with Apache License 2.0 6 votes vote down vote up
public Level toLevel(String sArg) {
    if (sArg == null) {
        return null;
    } else if (sArg.equalsIgnoreCase("ALL")) {
        return Level.ALL;
    } else if (sArg.equalsIgnoreCase("TRACE")) {
        return Level.TRACE;
    } else if (sArg.equalsIgnoreCase("DEBUG")) {
        return Level.DEBUG;
    } else if (sArg.equalsIgnoreCase("INFO")) {
        return Level.INFO;
    } else if (sArg.equalsIgnoreCase("WARN")) {
        return Level.WARN;
    } else if (sArg.equalsIgnoreCase("ERROR")) {
        return Level.ERROR;
    } else {
        return sArg.equalsIgnoreCase("OFF") ? Level.OFF : null;
    }
}
 
Example 8
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 9
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 10
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 11
Source File: MapAppenderUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    ctx = new LoggerContext();
    ctx.setName("test context");
    ctx.setStatusManager(new BasicStatusManager());
    mapAppender.setContext(ctx);
    mapAppender.setPrefix("prefix");
    event = new LoggingEvent("fqcn", ctx.getLogger("logger"), Level.INFO, "Test message for logback appender", null, new Object[0]);
    ctx.start();
}
 
Example 12
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 13
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;
}
 
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: LogUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Decode a string as a Level value.
 *
 * @param str the input string
 * @return the decoded Level value
 */
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 16
Source File: KafkaAppenderIT.java    From logback-kafka-appender with Apache License 2.0 4 votes vote down vote up
@Test
public void testLogging() {

    final int messageCount = 2048;
    final int messageSize = 1024;

    final Logger logger = loggerContext.getLogger("ROOT");

    unit.start();

    assertTrue("appender is started", unit.isStarted());

    final BitSet messages = new BitSet(messageCount);

    for (int i = 0; i < messageCount; ++i) {
        final String prefix = Integer.toString(i)+ ";";
        final StringBuilder sb = new StringBuilder();
        sb.append(prefix);
        byte[] b = new byte[messageSize-prefix.length()];
        ThreadLocalRandom.current().nextBytes(b);
        for(byte bb : b) {
            sb.append((char)bb & 0x7F);
        }

        final LoggingEvent loggingEvent = new LoggingEvent("a.b.c.d", logger, Level.INFO, sb.toString(), null, new Object[0]);
        unit.append(loggingEvent);
        messages.set(i);
    }

    unit.stop();
    assertFalse("appender is stopped", unit.isStarted());

    final KafkaConsumer<byte[], byte[]> javaConsumerConnector = kafka.createClient();
    javaConsumerConnector.assign(Collections.singletonList(new TopicPartition("logs", 0)));
    javaConsumerConnector.seekToBeginning(Collections.singletonList(new TopicPartition("logs", 0)));
    final long position = javaConsumerConnector.position(new TopicPartition("logs", 0));
    assertEquals(0, position);

    ConsumerRecords<byte[], byte[]> poll = javaConsumerConnector.poll(10000);
    int readMessages = 0;
    while (!poll.isEmpty()) {
        for (ConsumerRecord<byte[], byte[]> aPoll : poll) {
            byte[] msg = aPoll.value();
            byte[] msgPrefix = new byte[32];
            System.arraycopy(msg, 0, msgPrefix, 0, 32);
            final String messageFromKafka = new String(msgPrefix, UTF8);
            int delimiter = messageFromKafka.indexOf(';');
            final int msgNo = Integer.parseInt(messageFromKafka.substring(0, delimiter));
            messages.set(msgNo, false);
            readMessages++;
        }
        poll = javaConsumerConnector.poll(1000);
    }

    assertEquals(messageCount, readMessages);
    assertThat(fallbackLoggingEvents, empty());
    assertEquals("all messages should have been read", BitSet.valueOf(new byte[0]), messages);

}
 
Example 17
Source File: AbstractLoggingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
protected Level getTestLogLevel() {
	return Level.INFO;
}
 
Example 18
Source File: IntegrationPostHandler.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public IStatus post(URL url) throws MalformedURLException, IOException{
	Level logLevel = eventObject.getLevel();
	if (logLevel == null) {
		logLevel = Level.INFO;
	}
	
	JSONObject json = new JSONObject();
	
	if (identification != null) {
		json.put("username", identification);
	}
	
	ZonedDateTime eventTimeStamp =
		Instant.ofEpochMilli(eventObject.getTimeStamp()).atZone(ZoneId.of("GMT+1"));
	StringBuilder sbHeader = new StringBuilder();
	sbHeader
		.append(levelToEmoji(logLevel) + " " + eventTimeStamp.toLocalDateTime().format(dtf));
	sbHeader.append(" _" + eventObject.getLoggerName() + "_\n");
	String sbHeaderString = sbHeader.toString();
	
	String exception = parseException(eventObject);
	
	if (attachment) {
		json.put("text", sbHeaderString);
		
		Map<String, Object> params = new HashMap<>();
		params.put("color", levelToColor(logLevel));
		params.put("text", eventObject.getFormattedMessage());
		if (exception != null) {
			params.put("text", eventObject.getFormattedMessage() + exception);
		}
		
		json.put("attachments", Collections.singletonList(params));
	} else {
		StringBuilder sbBody = new StringBuilder();
		sbBody.append(levelToEmoji(logLevel));
		sbBody.append(eventObject.getFormattedMessage());
		if (exception != null) {
			sbBody.append("\n" + exception);
		}
		json.put("text", sbHeader + sbBody.toString());
	}
	
	return send(json.toString().getBytes(), url);
}
 
Example 19
Source File: AbstractConverterTest.java    From cf-java-logging-support with Apache License 2.0 4 votes vote down vote up
protected LoggingEvent makeEvent(String msg, Throwable t, Object[] args) {
    Logger logger = LoggerFactory.getLogger(this.getClass().getName());
    return new LoggingEvent(this.getClass().getName(), (ch.qos.logback.classic.Logger) logger, Level.INFO, msg, t,
                            args);
}
 
Example 20
Source File: MinMaxFilter.java    From baleen with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new instance of MinMaxFilter
 *
 * @param min The lowest level to log (inclusive), defaults to INFO if not provided
 * @param max The highest level to log (inclusive), defaults to the highest level, ERROR, if not
 *     provided
 */
public MinMaxFilter(Level min, Level max) {
  this.min = min == null ? Level.INFO : min;
  this.max = max == null ? Level.ERROR : max;
}