Logger"
Line 118: | Line 118: | ||
= Disable All Logs = | = Disable All Logs = | ||
− | Some logs are generated before loading <tt>i3-log.conf</tt>. If you want to disable all logs completely, you have to either configure the logging of the Web server<ref>Remember ZK uses the standard logging utilities. Unless you specify something in <tt>i3-log.conf</tt>, and the default logging levels depend on the Web server (usually <tt>INFO</tt>).</ref>, or specify <tt>log-level</tt> when configuring < | + | Some logs are generated before loading <tt>i3-log.conf</tt>. If you want to disable all logs completely, you have to either configure the logging of the Web server<ref>Remember ZK uses the standard logging utilities. Unless you specify something in <tt>i3-log.conf</tt>, and the default logging levels depend on the Web server (usually <tt>INFO</tt>).</ref>, or specify <tt>log-level</tt> when configuring <javadoc>org.zkoss.zk.ui.http.DHtmlLayoutServlet</javadoc> in <tt>WEB-INF/web.xml</tt>. For more information, please refer to [[ZK Configuration Reference/web.xml/ZK Loader|ZK Configuration Reference]]. |
<source lang="xml" > | <source lang="xml" > |
Revision as of 18:02, 26 November 2010
Class: Log
The logger used by ZK is based on the standard logger, java.util.Logger. However, we wrap it as Log to make it more efficient. The typical use is as follows.
import org.zkoss.util.logging.Log;
class MyClass {
private static final Log log = Log.lookup(MyClass.class);
public void f(Object v) {
if (log.debugable()) log.debug("Value is "+v);
}
}
Since ZK uses the standard logger to log message, you could control what to log by configuring the logging of the Web server you are using. How to configure the logging of the Web server varies from one server to another. Please consult the manuals. Or, you might use the logging configuration mechanism provided by ZK as described below.
By default, all ZK log instances are mapped to the same Java logger named org.zkoss to have the better performance. If you want to control the log level for individual class, you have to call Log.setHierarchy(boolean) to turn on the hierarchy support.
Log.setHierarchy(true);
The hierarchy support is enabled automatically, if you configure the log level with WEB-INF/zk.xml as described in the following section.
Configure Log Levels with ZK
In addition to configuring the logging of the Web server, you can use the logging configuration mechanism provided by ZK. By default, it is disabled. To enable it, you have to specify the following content in WEB-INF/zk.xml. Refer to ZK Configuration Reference fore more details.
<zk>
<log>
<log-base>org.zkoss</log-base>
</log>
</zk>
Alternatively, you can enable the logging configuration mechanism manually by invoking LogService.init(String, Class) as follows.
org.zkoss.util.logging.LogService.init("org.zkoss", null);
If you want to log not just org.zkoss but also everything, you could specify an empty value for the log-base argument.
Once the mechanism is enabled, ZK will look for i3-log.conf by searching the classpath at start-up and some particular locations (see below). If found, ZK loads its content to initialize the log levels. Then, ZK keeps watching this file, and reloads its content if the file is modified.
Content of i3-log.conf
An example of i3-log.conf is as follows.
org.zkoss.zk.ui.impl.UiEngineImpl=FINER
#Make the log level of the specified class to FINER
org.zkoss.zk.ui.http=DEBUG
#Make the log level of the specified package to DEBUG
org.zkoss.zk.au.http.DHtmlUpdateServlet=INHERIT
#Clear the log level of a specified class such that it inherits what
#has been defined above (Default: INFO)
org.zkoss.zk.ui=OFF
#Turn off the log for the specified package
org.zkoss=WARNING
#Make all log levels of ZK classes to WARNING except those specified here
Allowed Levels
Indicates no message at all. | |
Indicates providing error messages. | |
Indicates providing warning messages. It also implies ERROR. | |
Indicates providing informational messages. It also implies ERROR and WARNING. | |
Indicates providing tracing information for debugging purpose. It also implies ERROR, WARNING and INFO. | |
Indicates providing fairly detailed tracing information for debugging purpose. It also implies ERROR, WARNING, INFO and DEBUG | |
Indicates to clear any level being set to the specified package or class. In other words, the log level will be the same as its parent node. |
Location of i3-log.conf
At first, ZK looks for this file in the classpath. If not found, it looks for the conf directory.
Place i3-log.conf under the $TOMCAT_HOME/conf directory | |
Try the conf directory first. If not working, you could set the system property called the org.zkoss.io.conf.dir directory to be the directory where i3-log.conf resides. |
Disable All Logs
Some logs are generated before loading i3-log.conf. If you want to disable all logs completely, you have to either configure the logging of the Web server[1], or specify log-level when configuring DHtmlLayoutServlet in WEB-INF/web.xml. For more information, please refer to ZK Configuration Reference.
<servlet>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>log-level</param-name>
<param-value>OFF</param-value>
</init-param>
</servlet>
- ↑ Remember ZK uses the standard logging utilities. Unless you specify something in i3-log.conf, and the default logging levels depend on the Web server (usually INFO).
Version History
Version | Date | Content |
---|---|---|