Java Code Examples for ch.qos.logback.classic.spi.LoggingEvent#setLevel()
The following examples show how to use
ch.qos.logback.classic.spi.LoggingEvent#setLevel() .
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: MillisecondPrecisionSyslogStartConverterTest.java From logging-java with Apache License 2.0 | 6 votes |
@Test public void shouldLogContextPropertyHostname() { LoggerContext context = new LoggerContext(); context.putProperty("hostname", HOSTNAME); MillisecondPrecisionSyslogStartConverter millisecondPrecisionSyslogStartConverter = new MillisecondPrecisionSyslogStartConverter(); millisecondPrecisionSyslogStartConverter.setContext(context); millisecondPrecisionSyslogStartConverter.setOptionList(ImmutableList.of("LOCAL0")); millisecondPrecisionSyslogStartConverter.start(); LoggingEvent event = new LoggingEvent(); event.setLevel(Level.INFO); String message = millisecondPrecisionSyslogStartConverter.convert(event); assertTrue(message.contains(HOSTNAME)); }
Example 2
Source File: LoggerThresholdFilterTest.java From logging-java with Apache License 2.0 | 6 votes |
@Test public void verifyFilteringAllAtWarn() { final LoggerThresholdFilter filter = new LoggerThresholdFilter(); filter.setLevel(WARN); filter.start(); for(Level level : allLevels) { final LoggingEvent evt = new LoggingEvent(); evt.setLevel(level); for(String logger : variousLoggers) { evt.setLoggerName(logger); if(level.isGreaterOrEqual(WARN)) assertEquals(FilterReply.NEUTRAL, filter.decide(evt)); else assertEquals(FilterReply.DENY, filter.decide(evt)); } } }
Example 3
Source File: LoggerFilterTest.java From baleen with Apache License 2.0 | 5 votes |
private void assertNeutral(String logger, List<String> loggerName, Boolean exclude) { LoggerFilter filter = create(loggerName, exclude); LoggingEvent event = new LoggingEvent(); event.setLevel(Level.INFO); event.setLoggerName(logger); assertEquals(FilterReply.NEUTRAL, filter.decide(event)); }
Example 4
Source File: LevelRangeFilterTest.java From logging-java with Apache License 2.0 | 5 votes |
@Test public void verifyNoFilteringPassesAllEvents() { final List<Level> allLevels = asList(OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL); final LevelRangeFilter filter = new LevelRangeFilter(); filter.start(); for (final Level level : allLevels) { final LoggingEvent event = new LoggingEvent(); event.setLevel(level); assertEquals(FilterReply.NEUTRAL, filter.decide(event)); } }
Example 5
Source File: LoggerThresholdFilterTest.java From logging-java with Apache License 2.0 | 5 votes |
@Test public void verifyNoFilteringPassesAllEvents() { final LoggerThresholdFilter filter = new LoggerThresholdFilter(); filter.start(); for(Level level : allLevels) { final LoggingEvent evt = new LoggingEvent(); evt.setLevel(level); for(String logger : variousLoggers) { evt.setLoggerName(logger); assertEquals(FilterReply.NEUTRAL, filter.decide(evt)); } } }
Example 6
Source File: LoggerFilterTest.java From baleen with Apache License 2.0 | 5 votes |
private void assertDeny(String logger, List<String> loggerName, Boolean exclude) { LoggerFilter filter = create(loggerName, exclude); LoggingEvent event = new LoggingEvent(); event.setLevel(Level.INFO); event.setLoggerName(logger); assertEquals(FilterReply.DENY, filter.decide(event)); }
Example 7
Source File: CloudWatchAppender.java From cloudwatch-logback-appender with ISC License | 5 votes |
private LoggingEvent makeEvent(Level level, String message, Throwable th) { LoggingEvent event = new LoggingEvent(); event.setLoggerName(CloudWatchAppender.class.getName()); event.setLevel(level); event.setMessage(message); event.setTimeStamp(System.currentTimeMillis()); if (th != null) { event.setThrowableProxy(new ThrowableProxy(th)); } return event; }
Example 8
Source File: LoggerFilterTest.java From baleen with Apache License 2.0 | 5 votes |
private void assertDeny(String logger, String loggerName, Boolean exclude) { LoggerFilter filter = create(loggerName, exclude); LoggingEvent event = new LoggingEvent(); event.setLevel(Level.INFO); event.setLoggerName(logger); assertEquals(FilterReply.DENY, filter.decide(event)); }
Example 9
Source File: LoggerFilterTest.java From baleen with Apache License 2.0 | 5 votes |
private void assertNeutral(String logger, String loggerName, Boolean exclude) { LoggerFilter filter = create(loggerName, exclude); LoggingEvent event = new LoggingEvent(); event.setLevel(Level.INFO); event.setLoggerName(logger); assertEquals(FilterReply.NEUTRAL, filter.decide(event)); }
Example 10
Source File: JobMessageLogAppenderTest.java From edison-microservice with Apache License 2.0 | 5 votes |
private LoggingEvent createLoggingEvent(final Level level, final String message, final Object... params) { final LoggingEvent loggingEvent = new LoggingEvent(); loggingEvent.setMDCPropertyMap(singletonMap("job_id", "someJobId")); loggingEvent.setMessage(message); loggingEvent.setArgumentArray(params); loggingEvent.setLevel(level); loggingEvent.setMarker(JobMarker.JOB); return loggingEvent; }
Example 11
Source File: YarnTwillLogHandler.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void onLog(LogEntry logEntry) { final LoggingEvent loggingEvent = new LoggingEvent(); loggingEvent.setTimeStamp(logEntry.getTimestamp()); loggingEvent.setLoggerName(logEntry.getLoggerName()); loggingEvent.setLevel(Level.valueOf(logEntry.getLogLevel().name())); loggingEvent.setThreadName(logEntry.getThreadName()); Object [] formatObjects = new Object[] {logEntry.getHost(), getSimpleClassName(logEntry.getSourceClassName()), logEntry.getSourceMethodName(), logEntry.getFileName(), logEntry.getLineNumber(),logEntry.getMessage()}; loggingEvent.setMessage(MESSAGE_FORMAT.get().format(formatObjects)); // Prints the throwable and stack trace. LogThrowable logThrowable = logEntry.getThrowable(); if (logThrowable != null) { loggingEvent.setThrowableProxy(new ThrowableProxy(setThrowable(logThrowable))); } if (logger instanceof Logger) { ((Logger) logger).callAppenders(loggingEvent); } else { logger.info("Logger is not instance of ch.qos.logback.classic.Logger. Logger event is: {}", loggingEvent); } }
Example 12
Source File: GelfAppender.java From logback-gelf-appender with Apache License 2.0 | 4 votes |
@Override protected void append(ILoggingEvent event) { if (event == null) { return; } // create a copy of the logging event to avoid passing exception stacktraces to GELF's short_message field LoggingEvent copy = new LoggingEvent(); copy.setMessage(event.getMessage()); copy.setLevel(event.getLevel()); copy.setArgumentArray(event.getArgumentArray()); copy.setLoggerName(event.getLoggerName()); copy.setThreadName(event.getThreadName()); copy.setTimeStamp(event.getTimeStamp()); copy.setMDCPropertyMap(event.getMDCPropertyMap()); final GelfMessageBuilder builder = new GelfMessageBuilder(this.layout.doLayout(copy), hostName).timestamp( event.getTimeStamp() / 1000d) .level(GelfMessageLevel.fromNumericLevel(toGelfNumericValue(event.getLevel()))) .additionalField("loggerName", event.getLoggerName()) .additionalField("threadName", event.getThreadName()); final Marker marker = event.getMarker(); if (marker != null) { builder.additionalField("marker", marker.getName()); } if (includeMDC) { for (Map.Entry<String, String> entry : event.getMDCPropertyMap().entrySet()) { builder.additionalField(entry.getKey(), entry.getValue()); } } final StackTraceElement[] callerData = event.getCallerData(); if (includeSource && event.hasCallerData() && callerData.length > 0) { StackTraceElement source = callerData[0]; builder.additionalField("sourceFileName", source.getFileName()); builder.additionalField("sourceMethodName", source.getMethodName()); builder.additionalField("sourceClassName", source.getClassName()); builder.additionalField("sourceLineNumber", source.getLineNumber()); } final IThrowableProxy thrown = event.getThrowableProxy(); if (includeStackTrace && thrown != null) { String convertedThrowable = throwableConverter.convert(event); builder.additionalField("exceptionClass", thrown.getClassName()); builder.additionalField("exceptionMessage", thrown.getMessage()); builder.additionalField("exceptionStackTrace", convertedThrowable); builder.fullMessage(event.getFormattedMessage() + "\n\n" + convertedThrowable); } else { builder.fullMessage(event.getFormattedMessage()); } if (includeLevelName) { builder.additionalField("levelName", event.getLevel().levelStr); } if (!additionalFields.isEmpty()) { builder.additionalFields(additionalFields); } if(!client.trySend(builder.build())) { addError("Failed to write log event to the GELF server using trySend"); } }
Example 13
Source File: MinMaxFilterTest.java From baleen with Apache License 2.0 | 4 votes |
private void assertNeutral(Level level, Level min, Level max) { MinMaxFilter filter = create(min, max); LoggingEvent event = new LoggingEvent(); event.setLevel(level); assertEquals(FilterReply.NEUTRAL, filter.decide(event)); }
Example 14
Source File: MinMaxFilterTest.java From baleen with Apache License 2.0 | 4 votes |
private void assertDeny(Level level, Level min, Level max) { MinMaxFilter filter = create(min, max); LoggingEvent event = new LoggingEvent(); event.setLevel(level); assertEquals(FilterReply.DENY, filter.decide(event)); }
Example 15
Source File: ExceptionConverterTest.java From styx with Apache License 2.0 | 4 votes |
private ILoggingEvent newErrorLoggingEvent(Throwable throwable) { LoggingEvent loggingEvent = new LoggingEvent(); loggingEvent.setLevel(Level.ERROR); loggingEvent.setThrowableProxy(new ThrowableProxy(throwable)); return loggingEvent; }
Example 16
Source File: LoggerThresholdFilterTest.java From logging-java with Apache License 2.0 | 4 votes |
@Test public void filterSpotifyAtInfoOthersAtWarn() { List<Filter<ILoggingEvent>> filters = new ArrayList<Filter<ILoggingEvent>>(); LoggerThresholdFilter filter = new LoggerThresholdFilter(); filter.setLogger(spotifyLog); filter.setLevel(INFO); filter.start(); filters.add(filter); filter = new LoggerThresholdFilter(); filter.setExceptLogger(spotifyLog); filter.setLevel(WARN); filter.start(); filters.add(filter); for(Level level : allLevels) { final LoggingEvent evt = new LoggingEvent(); evt.setLevel(level); for(String logger : variousLoggers) { evt.setLoggerName(logger); FilterReply expected; FilterReply actual = FilterReply.NEUTRAL; if(spotifyLoggers.contains(logger)) { if(level.isGreaterOrEqual(INFO)) expected = FilterReply.NEUTRAL; else expected = FilterReply.DENY; } else { if(level.isGreaterOrEqual(WARN)) expected = FilterReply.NEUTRAL; else expected = FilterReply.DENY; } for(Filter<ILoggingEvent> logFilter : filters) { FilterReply nextReply = logFilter.decide(evt); actual = andFilterReplies(actual, nextReply); } assertEquals(String.format("Logger: %s, Level: %s", logger, level.toString()), expected, actual); } } }
Example 17
Source File: CloudWatchAppenderTest.java From cloudwatch-logback-appender with ISC License | 4 votes |
@Test(timeout = 5000) public void testInstanceName() throws InterruptedException { CloudWatchAppender appender = new CloudWatchAppender(); AWSLogsClient awsLogClient = createMock(AWSLogsClient.class); appender.setAwsLogsClient(awsLogClient); appender.setMaxBatchSize(1); appender.setRegion("region"); final String logGroup = "pfqoejpfqe"; appender.setLogGroup(logGroup); String prefix = "logstream-"; appender.setLogStream(prefix + "%instanceName"); final String expectedLogStream = prefix + "unknown"; PatternLayout layout = new PatternLayout(); layout.setPattern("%msg"); layout.start(); appender.setLayout(layout); LoggingEvent event = new LoggingEvent(); event.setTimeStamp(System.currentTimeMillis()); event.setLoggerName("name"); event.setLevel(Level.DEBUG); event.setMessage("message"); final PutLogEventsResult result = new PutLogEventsResult(); result.setNextSequenceToken("ewopjfewfj"); expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() { @Override public PutLogEventsResult answer() { PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0]; assertEquals(logGroup, request.getLogGroupName()); assertEquals(expectedLogStream, request.getLogStreamName()); return result; } }); awsLogClient.shutdown(); // ===================================== replay(awsLogClient); appender.start(); appender.append(event); while (appender.getEventsWrittenCount() < 1) { Thread.sleep(10); } appender.stop(); verify(awsLogClient); }
Example 18
Source File: CloudWatchAppenderTest.java From cloudwatch-logback-appender with ISC License | 4 votes |
@Test(timeout = 5000) public void testBasic() throws InterruptedException { CloudWatchAppender appender = new CloudWatchAppender(); AWSLogsClient awsLogClient = createMock(AWSLogsClient.class); appender.setAwsLogsClient(awsLogClient); appender.setMaxBatchSize(1); appender.setRegion("region"); final String logGroup = "pfqoejpfqe"; appender.setLogGroup(logGroup); final String logStream = "pffqjfqjpoqoejpfqe"; appender.setLogStream(logStream); PatternLayout layout = new PatternLayout(); layout.setContext(new LoggerContext()); layout.setPattern("[%thread] %level %logger{20} - %msg%n%xThrowable"); layout.start(); appender.setLayout(layout); LoggingEvent event = new LoggingEvent(); event.setTimeStamp(System.currentTimeMillis()); String loggerName = "name"; event.setLoggerName(loggerName); Level level = Level.DEBUG; event.setLevel(level); String message = "fjpewjfpewjfpewjfepowf"; event.setMessage(message); String threadName = Thread.currentThread().getName(); final String fullMessage = "[" + threadName + "] " + level + " " + loggerName + " - " + message + "\n"; final PutLogEventsResult result = new PutLogEventsResult(); String sequence = "ewopjfewfj"; result.setNextSequenceToken(sequence); expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() { @Override public PutLogEventsResult answer() { PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0]; assertEquals(logGroup, request.getLogGroupName()); assertEquals(logStream, request.getLogStreamName()); List<InputLogEvent> events = request.getLogEvents(); assertEquals(1, events.size()); assertEquals(fullMessage, events.get(0).getMessage()); return result; } }).times(2); awsLogClient.shutdown(); // ===================================== replay(awsLogClient); appender.start(); // for coverage appender.start(); appender.append(event); Thread.sleep(10); appender.append(event); while (appender.getEventsWrittenCount() < 2) { Thread.sleep(10); } appender.stop(); verify(awsLogClient); }