Logger"
m (correct highlight (via JWB)) |
|||
Line 5: | Line 5: | ||
Package: <javadoc>org.zkoss.util.logging.Log</javadoc> | Package: <javadoc>org.zkoss.util.logging.Log</javadoc> | ||
− | The logger used by ZK is based on the standard logger, < | + | The logger used by ZK is based on the standard logger, <code>java.util.Logger</code>. However, we wrap it as <javadoc>org.zkoss.util.logging.Log</javadoc> to make it more efficient. The typical use is as follows. |
<source lang="java" > | <source lang="java" > | ||
Line 19: | Line 19: | ||
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. | 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. | ||
− | '''Note''': By default, all ZK log instances are mapped to the same Java logger named < | + | '''Note''': By default, all ZK log instances are mapped to the same Java logger named <code>org.zkoss</code> to have the better performance. If you want to control the log level up to individual class, you have to invoke the following statement to turn on the hierarchy support. |
− | < | + | <code>Log.setHierarchy(true);</code> |
− | '''Note''': The hierarchy support is enabled automatically, if you configure the log level with < | + | '''Note''': The hierarchy support is enabled automatically, if you configure the log level with <code>WEB-INF/zk.xml</code> as described in the following section. |
=== How to Configure Log Levels with ZK === | === How to 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 < | + | 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 <code>WEB-INF/zk.xml</code>. Refer to [http://books.zkoss.org/wiki/ZK_Configuration_Reference ZK Configuration Reference] fore more details. |
<source lang="xml" > | <source lang="xml" > | ||
Line 36: | Line 36: | ||
</source> | </source> | ||
− | Alternatively, you can enable the logging configuration mechanism manually by invoking the < | + | Alternatively, you can enable the logging configuration mechanism manually by invoking the <code>init</code> method of <code>LogService</code> as follows. |
<source lang="xml" > | <source lang="xml" > | ||
Line 42: | Line 42: | ||
</source> | </source> | ||
− | If you want to log not just < | + | If you want to log not just <code>org.zkoss</code> but also everything, you could specify an empty value for <code>log-base</code>. |
− | Once the mechanism is enabled, ZK looks for < | + | Once the mechanism is enabled, ZK looks for <code>i3-log.conf</code> 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 === | === Content of i3-log.conf === | ||
− | An example of < | + | An example of <code>i3-log.conf</code> is as follows. |
<source lang="xml" > | <source lang="xml" > | ||
Line 99: | Line 99: | ||
|} | |} | ||
=== Location of i3-log.conf === | === Location of i3-log.conf === | ||
− | At first, ZK looks for this file in the classpath. If not found, it looks for the < | + | At first, ZK looks for this file in the classpath. If not found, it looks for the <code>conf</code> directory. |
Line 108: | Line 108: | ||
|- | |- | ||
| <center>Tomcat</center> | | <center>Tomcat</center> | ||
− | | Place < | + | | Place <code>i3-log.conf</code> under the <code>$TOMCAT_HOME/conf</code> directory |
|- | |- | ||
| <center>Others</center> | | <center>Others</center> | ||
− | | Try the conf directory first. If not working, you could set the system property called the < | + | | Try the conf directory first. If not working, you could set the system property called the <code>org.zkoss.io.conf.dir</code> directory to be the directory where <code>i3-log.conf</code> resides. |
|} | |} | ||
=== Disable All Logs === | === Disable All Logs === | ||
− | Some logs are generated before loading < | + | Some logs are generated before loading <code>i3-log.conf</code>. 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 <code>i3-log.conf</code>, and the default logging levels depend on the Web server (usually <code>INFO</code>).</ref>, or specify <code>log-level</code> when configuring <code>DHtmlLayoutServlet</code> in <code>WEB-INF/web.xml</code>. Refer to '''the Developer's Reference''' for details. |
<source lang="xml" > | <source lang="xml" > |
Latest revision as of 10:35, 19 January 2022
This documentation is for an older version of ZK. For the latest one, please click here.
Package: 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.
Note: 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 up to individual class, you have to invoke the following statement to turn on the hierarchy support.
Log.setHierarchy(true);
Note: The hierarchy support is enabled automatically, if you configure the log level with WEB-INF/zk.xml
as described in the following section.
How to 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 the init
method of LogService
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 log-base
.
Once the mechanism is enabled, ZK looks 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
. Refer to the Developer's Reference for details.
<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>
<init-param>
<param-name>compress</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
Notes
- ↑ 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 (usuallyINFO
).