java
LogBack Message ILoggingEvent
I have a class that extends LayoutBase. In the doLayout method, I add a key to my logging called MSG and the value is set to ILoggingEvent event.getMessage(). I'm seeing values added to my logging but they're not consistent; some logging messages and some exception stack traces. Can anyone tell me where ILoggingEvent event.getMessage() gets its value from?
Please refer to Logback architecture It mentions that each log will go through series of step Get Filter Chain Decision If it exists, the TurboFilter chain is invoked. Turbo filters can set a context-wide threshold, or filter out certain events based on information such as Marker, Level, Logger, message, or the Throwable that are associated with each logging request. Apply the selection rule At this step, logback compares the effective level of the logger with the level of the request. If the logging request is disabled according to this test, then logback will drop the request without further processing. Create a LoggingEvent object If the request survived the previous filters, logback will create a LoggingEvent object containing all the relevant parameters of the request Invoking appenders After the creation of a LoggingEvent object, logback will invoke the doAppend() methods of all the applicable appenders, that is, the appenders inherited from the logger context. Formatting the output It is the responsibility of the invoked appender to format the logging event. However, some (but not all) appenders delegate the task of formatting the logging event to a layout. Sending out the LoggingEvent After the logging event is fully formatted it is sent to its destination by each appender. I'm seeing values added to my logging but they're not consistent; some logging messages and some exception stack traces. Now, coming to your query, it seems that you are receiving events which have exception information (Throwable) during the formatting step. You can create a CustomFilter to filter out such events. All you have to do is extends Filter<ILoggingEvent> public class DenyExceptionFilter extends Filter<ILoggingEvent> { #Override public FilterReply decide(ILoggingEvent iLoggingEvent) { final IThrowableProxy throwableProxy = iLoggingEvent.getThrowableProxy(); if (throwableProxy != null && throwableProxy instanceof ThrowableProxy) return FilterReply.DENY; return FilterReply.ACCEPT; } } This can be much more powerful, can filter specific types of exception. You can take this as your homework :P Then you can add this Custom Filter to your appender as <appender name="APPENDER_NAME" class="ch.qos.logback.classic.AsyncAppender"> <filter class="com.stackoverflow.DenyExceptionFilter" /> </appender> Of course, add your layout as well after the filter.
Related Links
ODBC Error: Invalid String or Buffer Length--Microsoft Server 2008 32bit vs 2008 R2 64bit
Is there any Java Look and Feel implementation using only console?
Implement probability distribution function in Java problem
Java JTextArea handling undisplayable ASCII sequences
Java - Using Hashtable with Interface as value
Java installer with support for windows service
Why should i give a name to an If Statement?
BaseAdapter in ListActivity isn't displaying the correct items
Java dump an object
Why use a bitwise AND here?
Java HTML files and JEditor Pane
Checking JAR Usage at the Package Level
I'm really having trouble figuring out how to make my GUI window display the values in the array
Create a file object from a resource path to an image in a jar file
Java Object[] cast to long[][] performance issuse?
Does “/* (non-javadoc)” have a well-understood meaning?