Wiki source code of Logging

Version 11.3 by Vincent Massol on 2012/04/29

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

Get Connected