public class WicketWebFormattingConverter extends AbstractWebFormattingConverter
A custom logback conversion word converter. By registering this converter (through
<conversionRule>
element in logback config) and using the "%web" conversion word
in the logback encoder pattern wicket apps can produce web information (method, url, session id,
...) in their log messages. If there is no request information available the placeholder is
replaced with an empty string in the final message.
Example logback configuration:
<conversionRule conversionWord="web"
converterClass="org.wicketstuff.logback.WicketWebFormattingConverter" />
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d|%p|%t|%c{36}|%r|<b>%web</b>%n\t%caller{1}\t%m%n%xEx</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>debug</level>
</filter>
</appender>
The above will result in log messages like this:
2011-02-21 14:18:26,281|INFO|"http-nio-8080"-exec-2|o.w.logback.examples.HomePage|28066|GET http://localhost:8080/wicketstuff-logback-examples/?null null null 127.0.0.1:59363 127.0.0.1:8080 null Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13
Caller+0 at org.wicketstuff.logback.examples.HomePage.(HomePage.java:19)
Logging is good - said the lumberjack.
The full message format is available in the javadoc of AbstractWebFormattingConverter
.
There are similar solutions using Filter
-s, MDC and NDC to solve the same task (like
logback's own MDCInsertingServletFilter or spring's AbstractRequestLoggingFilter and its
subclasses). The difference from those is performance (and the amount of information provided).
Those filters are always collecting information for every request however usually only a small
portion of requests result in actual logging. This solution only gets invoked when the logging
event is indeed producing a log message. It is on the "other side of the fence".
Implementation of AbstractWebFormattingConverter
that uses wicket to locate the current
HttpServletRequest
object in getRequest()
method. Registerable through
<conversionRule>
element in logback config.
Modifier and Type | Field and Description |
---|---|
static String |
CONVERSION_WORD
This is the word that can be used in the layout pattern: "web".
|
RA_WEB_INFO
Constructor and Description |
---|
WicketWebFormattingConverter() |
Modifier and Type | Method and Description |
---|---|
protected javax.servlet.http.HttpServletRequest |
getRequest() |
convert, getWebString
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getFirstOption, getOptionList, isStarted, setContext, setOptionList, start, stop
public static final String CONVERSION_WORD
protected javax.servlet.http.HttpServletRequest getRequest()
getRequest
in class AbstractWebFormattingConverter
Copyright © 2015. All rights reserved.