Wiki source code of Logging

Version 23.1 by Jean-Sébastien Dennebouy on 2021/03/25

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 = Log Location =
10
11 == Main Logs ==
12
13 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.
14
15 Here are some potential locations you can check, depending on the [[installation method>>xwiki:Documentation.AdminGuide.Installation.WebHome#HInstallationMethods]] you've chosen::
16
17 * If you use the [[XWiki Debian packaging>>xwiki:Documentation.AdminGuide.Installation.InstallationViaAPT.WebHome]], and thus using Tomcat, it's in ##/var/log/tomcat*/catalina.out##
18 ** Recent Tomcat packages use service logs, visible using the command ##journalctl -u tomcat9.service##
19 * If you use the [[XWiki Docker packaging>>https://github.com/xwiki-contrib/docker-xwiki/blob/master/README.md]] it's in the console that started Tomcat, or if you started it in background, you can get them with ##docker logs <container id>##.
20 * If you use the [[XWiki Standalone packaging>>Documentation.AdminGuide.InstallationStandalone]], then it's in the console and also in ##data/logs/<date>.output.log##.
21 * If you use the [[Manual WAR packaging>>Documentation.AdminGuide.InstallationWAR]], then it depends on the Servlet engine you've used and how you've configured it. You could check in ##/var/log/tomcat*/catalina.out## on unix or ##<tomcat home>/logs/catalina.out## for Tomcat.
22
23 == Job Logs ==
24
25 XWiki has the concept of [[jobs>>extensions:Extension.Job Module.WebHome]] (e.g. when you install or upgrade an Extension or when you delete pages, they all execute in a job). Very often, jobs capture the logs and output them in job log files located in the [[permanent directory>>Documentation.AdminGuide.Configuration.WebHome#HPermanentDirectory]], under the ##jobs## subdirectories. Log files are named ##log.xml##.
26
27 Note that some features allow you to see view these logs in the UI. For exampe the Extension Manager has a UI so that you can [[review the logs when an extension was installed, or updated>>extensions:Extension.Extension Manager Application#HProgressLog]].
28
29 = Configuring Logging =
30
31 There are various ways in which you can configure what to log.
32
33 See also the [[Logging section of the Debugging page>>dev:Community.Debugging#HLogging]] for specific details on some loggers.
34
35 {{info}}
36 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.
37 {{/info}}
38
39 == Manually ==
40
41 Simply edit the Logback configuration file (##logback.xml## in ##WEB-INF/classes## in your web application folder) and restart the Servlet container for it to take effect.
42
43 == Using the Log Application ==
44
45 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.
46
47 == Using JMX ==
48
49 [[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.
50
51 See the [[Monitoring Guide>>Documentation.AdminGuide.Monitoring]] for more details on using JMX with XWiki.
52
53 = Analyzing logs with Lilith =
54
55 [[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:
56
57 {{code language="xml"}}
58 ...
59 <appender name="socket" class="ch.qos.logback.classic.net.SocketAppender">
60 <RemoteHost>localhost</RemoteHost>
61 <Port>4560</Port>
62 <ReconnectionDelay>170</ReconnectionDelay>
63 <IncludeCallerData>true</IncludeCallerData>
64 </appender>
65 ...
66 {{/code}}
67
68 And add the new appender to the list of appenders to use. For example:
69
70 {{code language="xml"}}
71 ...
72 <root level="warn">
73 <appender-ref ref="stdout"></appender-ref>
74 <appender-ref ref="socket"></appender-ref>
75 </root>
76 ...
77 {{/code}}
78
79 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.
80
81 For example:
82
83 [[image:lilith.png||width="950"]]
84
85 == Using a different SLF4J implementation ==
86
87 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]]):
88
89 * Remove the Logback SLF4J implementation from the classpath by removing ##WEB-INF/lib/logback-classic-*.jar## and ##WEB-INF/lib/logback-core-*.jar##
90 * Remove the Log4J over SLF4J JAR from the classpath by removing ##WEB-INF/lib/log4j-over-slf4j-*.jar##
91 * Add the Log4J SLF4J implementation to the classpath: ##slf4j-log4j*-*.jar##
92 * Add Log4J itself to the classpath
93
94 = Older XWiki versions =
95
96 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.
97
98 {{info}}
99 By default XWiki was configured to log everything on the console only.
100 {{/info}}
101
102 == Using a custom Log4J configuration ==
103
104 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:
105
106 {{code language="none"}}
107 ### Direct log messages to stdout
108 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
109 log4j.appender.stdout.Target=System.out
110 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
111 log4j.appender.stdout.layout.ConversionPattern=%d [%X{url}] [%t] %-5p %-30.30c{2} %x - %m %n
112
113 ### By default everything that is of warning or severity WARN, ERROR or FATAL is logged both to
114 ### the console and to the xwiki.log file.
115 log4j.rootLogger=warn, stdout
116
117 ### Hibernate logging options
118 log4j.logger.org.hibernate=warn
119 log4j.logger.org.hibernate.SQL=warn
120 log4j.logger.org.hibernate.type=warn
121 log4j.logger.org.hibernate.ps.PreparedStatementCache=warn
122
123 ### XWiki logging configuration
124 log4j.logger.org.xwiki=info
125 log4j.logger.com.xpn.xwiki=warn
126 log4j.logger.com.xpn.xwiki.render.XWikiRadeoxRenderEngine=warn
127 log4j.logger.com.xpn.xwiki.store.migration=info
128
129 ### Deactive Struts warnings
130 log4j.logger.org.apache.struts.util.RequestUtils=error
131
132 ### Deactivate JGroups warnings
133 log4j.logger.org.jgroups=error
134
135 ## Deactive PDF Export CSS Applier warnings
136 log4j.logger.info.informatica.doc.style.css.dom=error
137 log4j.logger.org.apache.fop.layoutmgr.inline.ContentLayoutManager=error
138 {{/code}}
139
140 Refer to Log4J's documentation to understand the settings. As an example, to turn on Hibernate's calls, just set the following:
141
142 {{code}}
143 log4j.logger.org.hibernate.SQL=debug
144 {{/code}}
145
146 = Activating the XWiki Monitoring feature =
147
148 {{info}}
149 The monitoring feature is already active in the default configuration.
150 {{/info}}
151
152 XWiki has a feature to monitor times spent in its major components. To activate it, you need to:
153
154 * Enable the Monitor plugin by adding/modifying the following plugin definition in the ##xwiki.cfg## configuration file:(((
155 {{code language="none"}}
156 xwiki.plugins=\
157 [...]
158 com.xpn.xwiki.monitor.api.MonitorPlugin
159 {{/code}}
160 )))
161 * Enable it by adding/modifying the following in the ##xwiki.cfg## configuration file:(((
162 {{code language="none"}}
163 xwiki.monitor=1
164 {{/code}}
165 )))
166 * 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.(((
167 For example for Logback it means adding the following in ##logback.xml##:
168
169 {{code language="none"}}
170 <logger name="com.xpn.xwiki.monitor" level="debug"></logger>
171 {{/code}}
172
173 And for older XWiki versions using Log4J it means adding the following in ##log4j.properties##:
174
175 {{code language="none"}}
176 log4j.logger.com.xpn.xwiki.monitor=debug
177 {{/code}}
178 )))

Get Connected