Wiki source code of Logging

Version 12.2 by Manuel Smeria on 2012/12/18

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 = For XWiki 3.1 and beyond =
6
7 Starting with version 3.1 XWiki logs using [[SLF4J>>http://www.slf4j.org/]]. By default XWiki is configured so that SLF4J uses [[Logback>>http://logback.qos.ch/]]. XWiki's Logback configuration is located in the ##[[WEB-INF/classes/logback.xml>>https://raw.github.com/xwiki/xwiki-platform/master/xwiki-platform-core/xwiki-platform-web/src/main/resources/logback.xml]]## file.
8
9 XWiki is also configured by default so that any logs generated by 3rd part JARs used by XWiki (i.e. in the XWiki classpath at runtime) will automatically find their ways to the output defined by the Logback configuration file. This is active for Apache Commons Logging (JCL) and Log4J. This is achieved by using [[a SLF4J Bridge>>http://www.slf4j.org/legacy.html]] for both logging frameworks (it's the ##log4j-over-slf4j-*.jar## and ##jcl-over-slf4j-*.jar## files that provide this feature).
10
11 To customize the Logback configuration simply edit the file and restart the Servlet container for it to take effect.
12
13 {{info}}
14 By default XWiki is configured to log everything on the console only.
15 {{/info}}
16
17 == Using JMX to change the logging configuration ==
18
19 [[LogBack exposes its configuration with JMX>>http://logback.qos.ch/manual/jmxConfig.html]] making it possible to use a JMX console to modify the logging configuration at runtime, thus not needing to restart the Servlet container. This is very useful in production when needing to debug an issue.
20
21 See the [[Monitoring Guide>>AdminGuide.Monitoring]] for more details on using JMX with XWiki.
22
23 == Analyzing logs with Lilith ==
24
25 [[Lilith>>http://lilith.huxhorn.de/]] is a logging and access event viewer. It makes it easy to analyze large quantities of logs. To use it, configure XWiki's Logging to send events to the Socket appender. Add the following to the ##logback.xml## file:
26
27 {{code language="xml"}}
28 ...
29 <appender name="socket" class="ch.qos.logback.classic.net.SocketAppender">
30 <RemoteHost>localhost</RemoteHost>
31 <Port>4560</Port>
32 <ReconnectionDelay>170</ReconnectionDelay>
33 <IncludeCallerData>true</IncludeCallerData>
34 </appender>
35 ...
36 {{/code}}
37
38 And add the new appender to the list of appenders to use. For example:
39
40 {{code language="xml"}}
41 ...
42 <root level="warn">
43 <appender-ref ref="stdout"/>
44 <appender-ref ref="socket"/>
45 </root>
46 ...
47 {{/code}}
48
49 Open Lilith (it's a desktop application) and it'll automatically listen on port 4560 so when you start XE you'll see its logs show up in Lilith.
50
51 For example:
52
53 [[image:lilith.png||style="width:950px"]]
54
55 == Using a different SLF4J implementation ==
56
57 If you wish, for example, to use Log4J to log all logs produced by XWiki you can do so by doing the following ([[described in the SLF4J manual>>hhttp://www.slf4j.org/manual.html]]):
58 * Remove the Logback SLF4J implementation from the classpath by removing ##WEB-INF/lib/logback-classic-*.jar## and ##WEB-INF/lib/logback-core-*.jar##
59 * Remove the Log4J over SLF4J JAR from the classpath by removing ##WEB-INF/lib/log4j-over-slf4j-*.jar##
60 * Add the Log4J SLF4J implementation to the classpath: ##slf4j-log4j*-*.jar##
61 * Add Log4J itself to the classpath
62
63 = For older XWiki versions =
64
65 XWiki versions 3.0 and older use Commons Logging for logging. By default XWiki is configured so that Commons Logging uses log4J. XWiki's Log4J configuration is located inside XWiki's JAR (xwiki-core-x.y.jar), in a ##[[log4j.properties>>https://raw.github.com/xwiki/xwiki-platform/13e01088e74c170452088a56fe54fb76a7ecb041/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/log4j.properties]]## file. XWiki' JAR is itself located in your ##WEB-INF/lib/## directory.
66
67 {{info}}
68 By default XWiki is configured to log everything on the console only.
69 {{/info}}
70
71 == Using a custom Log4J configuration ==
72
73 The best solution is to create a new ##log4j.properties## file in your ##WEB-INF/classes## directory. It'll thus override the one from the XWiki JAR. As an example, here's a sample configuration:
74
75 {{code language="none"}}
76 ### Direct log messages to stdout
77 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
78 log4j.appender.stdout.Target=System.out
79 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
80 log4j.appender.stdout.layout.ConversionPattern=%d [%X{url}] [%t] %-5p %-30.30c{2} %x - %m %n
81
82 ### By default everything that is of warning or severity WARN, ERROR or FATAL is logged both to
83 ### the console and to the xwiki.log file.
84 log4j.rootLogger=warn, stdout
85
86 ### Hibernate logging options
87 log4j.logger.org.hibernate=warn
88 log4j.logger.org.hibernate.SQL=warn
89 log4j.logger.org.hibernate.type=warn
90 log4j.logger.org.hibernate.ps.PreparedStatementCache=warn
91
92 ### XWiki logging configuration
93 log4j.logger.org.xwiki=info
94 log4j.logger.com.xpn.xwiki=warn
95 log4j.logger.com.xpn.xwiki.render.XWikiRadeoxRenderEngine=warn
96 log4j.logger.com.xpn.xwiki.store.migration=info
97
98 ### Deactive Struts warnings
99 log4j.logger.org.apache.struts.util.RequestUtils=error
100
101 ### Deactivate JGroups warnings
102 log4j.logger.org.jgroups=error
103
104 ## Deactive PDF Export CSS Applier warnings
105 log4j.logger.info.informatica.doc.style.css.dom=error
106 log4j.logger.org.apache.fop.layoutmgr.inline.ContentLayoutManager=error
107 {{/code}}
108
109 Refer to Log4J's documentation to understand the settings. As an example, to turn on Hibernate's calls, just set the following:
110
111 {{code}}
112 log4j.logger.org.hibernate.SQL=debug
113 {{/code}}
114
115 = Activating the XWiki Monitoring feature =
116
117 {{info}}
118 The monitoring feature is already active in the default configuration.
119 {{/info}}
120
121 XWiki has a feature to monitor times spent in its major components. To activate it, you need to:
122
123 * Enable the Monitor plugin by adding/modifying the following plugin definition in the ##xwiki.cfg## configuration file:
124 (((
125 {{code language="none"}}
126 xwiki.plugins=\
127 [...]
128 com.xpn.xwiki.monitor.api.MonitorPlugin
129 {{/code}}
130 )))
131 * Enable it by adding/modifying the following in the ##xwiki.cfg## configuration file:
132 (((
133 {{code language="none"}}
134 xwiki.monitor=1
135 {{/code}}
136 )))
137 * Since the plugin logs everything under the ##DEBUG## severity you also need to configure the XWiki Logging (as described above) by setting the ##com.xpn.xwiki.monitor## category to the ##DEBUG## level.
138 (((
139 For example for Logback it means adding the following in ##logback.xml##:
140
141 {{code language="none"}}
142 <logger name="com.xpn.xwiki.monitor" level="debug"/>
143 {{/code}}
144
145 And for older XWiki versions using Log4J it means adding the following in ##log4j.properties##:
146
147 {{code language="none"}}
148 log4j.logger.com.xpn.xwiki.monitor=debug
149 {{/code}}
150 )))

Get Connected