Wiki source code of Logging

Version 19.1 by Anca Luca on 2014/10/15

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 XWiki uses [[SLF4J>>http://www.slf4j.org/]] for logging. 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.
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## files that provide this feature).
8
9 {{info}}
10 By default XWiki is configured to log everything on the console only. Whether the console is captured by your Servlet Container or not depends on the container you use. For example Tomcat on unix will capture stdout and add logs to the ##tomcat/logs/catalina.out## file.
11 {{/info}}
12
13 = Configuring Logging =
14
15 There are various ways in which you can configure what to log.
16
17 See also the [[Logging section of the Debugging page>>dev:Community.Debugging#HLogging]] for specific details on some loggers.
18
19 {{info}}Of the 3 methods proposed under, only the Manual method is persistent **after a server restart**. So if your server might restart/be restarted and you want the log configuration to be kept after this restart, the only method is adding them to logback.xml.{{/info}}
20
21 == Manually ==
22
23 Simply edit the Logback configuration file (##logback.xml##) and restart the Servlet container for it to take effect.
24
25 == Using the Log Application ==
26
27 Starting with XWiki 4.2 a new [[Logging Application>>extensions:Extension.Logging Application]] is available in your wiki's administration UI and you can use it to configure the log levels for all features.
28
29 == Using JMX ==
30
31 [[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.
32
33 See the [[Monitoring Guide>>AdminGuide.Monitoring]] for more details on using JMX with XWiki.
34
35 = Analyzing logs with Lilith =
36
37 [[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:
38
39 {{code language="xml"}}
40 ...
41 <appender name="socket" class="ch.qos.logback.classic.net.SocketAppender">
42 <RemoteHost>localhost</RemoteHost>
43 <Port>4560</Port>
44 <ReconnectionDelay>170</ReconnectionDelay>
45 <IncludeCallerData>true</IncludeCallerData>
46 </appender>
47 ...
48 {{/code}}
49
50 And add the new appender to the list of appenders to use. For example:
51
52 {{code language="xml"}}
53 ...
54 <root level="warn">
55 <appender-ref ref="stdout"/>
56 <appender-ref ref="socket"/>
57 </root>
58 ...
59 {{/code}}
60
61 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.
62
63 For example:
64
65 [[image:lilith.png||style="width:950px"]]
66
67 == Using a different SLF4J implementation ==
68
69 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]]):
70 * Remove the Logback SLF4J implementation from the classpath by removing ##WEB-INF/lib/logback-classic-*.jar## and ##WEB-INF/lib/logback-core-*.jar##
71 * Remove the Log4J over SLF4J JAR from the classpath by removing ##WEB-INF/lib/log4j-over-slf4j-*.jar##
72 * Add the Log4J SLF4J implementation to the classpath: ##slf4j-log4j*-*.jar##
73 * Add Log4J itself to the classpath
74
75 = Older XWiki versions =
76
77 XWiki versions 3.0 and older use Commons Logging for logging. By default XWiki was configured so that Commons Logging was using log4J. XWiki's Log4J configuration was 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.
78
79 {{info}}
80 By default XWiki was configured to log everything on the console only.
81 {{/info}}
82
83 == Using a custom Log4J configuration ==
84
85 The best solution was 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:
86
87 {{code language="none"}}
88 ### Direct log messages to stdout
89 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
90 log4j.appender.stdout.Target=System.out
91 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
92 log4j.appender.stdout.layout.ConversionPattern=%d [%X{url}] [%t] %-5p %-30.30c{2} %x - %m %n
93
94 ### By default everything that is of warning or severity WARN, ERROR or FATAL is logged both to
95 ### the console and to the xwiki.log file.
96 log4j.rootLogger=warn, stdout
97
98 ### Hibernate logging options
99 log4j.logger.org.hibernate=warn
100 log4j.logger.org.hibernate.SQL=warn
101 log4j.logger.org.hibernate.type=warn
102 log4j.logger.org.hibernate.ps.PreparedStatementCache=warn
103
104 ### XWiki logging configuration
105 log4j.logger.org.xwiki=info
106 log4j.logger.com.xpn.xwiki=warn
107 log4j.logger.com.xpn.xwiki.render.XWikiRadeoxRenderEngine=warn
108 log4j.logger.com.xpn.xwiki.store.migration=info
109
110 ### Deactive Struts warnings
111 log4j.logger.org.apache.struts.util.RequestUtils=error
112
113 ### Deactivate JGroups warnings
114 log4j.logger.org.jgroups=error
115
116 ## Deactive PDF Export CSS Applier warnings
117 log4j.logger.info.informatica.doc.style.css.dom=error
118 log4j.logger.org.apache.fop.layoutmgr.inline.ContentLayoutManager=error
119 {{/code}}
120
121 Refer to Log4J's documentation to understand the settings. As an example, to turn on Hibernate's calls, just set the following:
122
123 {{code}}
124 log4j.logger.org.hibernate.SQL=debug
125 {{/code}}
126
127 = Activating the XWiki Monitoring feature =
128
129 {{info}}
130 The monitoring feature is already active in the default configuration.
131 {{/info}}
132
133 XWiki has a feature to monitor times spent in its major components. To activate it, you need to:
134
135 * Enable the Monitor plugin by adding/modifying the following plugin definition in the ##xwiki.cfg## configuration file:
136 (((
137 {{code language="none"}}
138 xwiki.plugins=\
139 [...]
140 com.xpn.xwiki.monitor.api.MonitorPlugin
141 {{/code}}
142 )))
143 * Enable it by adding/modifying the following in the ##xwiki.cfg## configuration file:
144 (((
145 {{code language="none"}}
146 xwiki.monitor=1
147 {{/code}}
148 )))
149 * 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.
150 (((
151 For example for Logback it means adding the following in ##logback.xml##:
152
153 {{code language="none"}}
154 <logger name="com.xpn.xwiki.monitor" level="debug"/>
155 {{/code}}
156
157 And for older XWiki versions using Log4J it means adding the following in ##log4j.properties##:
158
159 {{code language="none"}}
160 log4j.logger.com.xpn.xwiki.monitor=debug
161 {{/code}}
162 )))

Get Connected