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