Logger"
(→How to Configure Logging: add jdk logging reference) |
RebeccaLai (talk | contribs) m |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
__TOC__ | __TOC__ | ||
− | In this section we describe how to configure the logging of ZK internal functions. You | + | In this section we describe how to configure the logging of ZK internal functions. You can generally ignore it, unless you'd like to know how ZK operates internally. |
Notice that, if you are using Google App Engine, you can ''not'' configure the logging as described in this chapter. For more information, please refer to [[ZK Installation Guide/Setting up Servers/Google App Engine|Setting up Google App Engine]]. | Notice that, if you are using Google App Engine, you can ''not'' configure the logging as described in this chapter. For more information, please refer to [[ZK Installation Guide/Setting up Servers/Google App Engine|Setting up Google App Engine]]. | ||
=How to Configure Logging= | =How to Configure Logging= | ||
− | + | ||
+ | {{versionSince| 7.0.0}} | ||
+ | |||
ZK uses [http://www.slf4j.org/ SLF4J] as its internal logging system, and developers can follow the [http://www.slf4j.org/manual.html SLF4J document] to use the logging in ZK. | ZK uses [http://www.slf4j.org/ SLF4J] as its internal logging system, and developers can follow the [http://www.slf4j.org/manual.html SLF4J document] to use the logging in ZK. | ||
By default, ZK maven setting will bundle the '''slf4j-jdk14''' implementation as its default logging.<ref>https://docs.oracle.com/cd/E19717-01/819-7753/gcbkm/index.html</ref> | By default, ZK maven setting will bundle the '''slf4j-jdk14''' implementation as its default logging.<ref>https://docs.oracle.com/cd/E19717-01/819-7753/gcbkm/index.html</ref> | ||
− | If | + | If developers want to change that implementation for '''Log4j''', '''Simple''', or '''Logback''', they have to exclude the dependency first like: |
<source lang="xml"> | <source lang="xml"> | ||
Line 26: | Line 28: | ||
</dependency> | </dependency> | ||
</source> | </source> | ||
− | + | ||
+ | |||
+ | {{versionSince| 9.5.0}} | ||
+ | |||
+ | ZK maven dropped the transitive dependency of '''slf4j-jdk14'''. If a developer decides to enable logging, include either '''Log4j''', '''Simple''', or '''Logback''' implementation in their maven pom.xml file, e.g. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <dependency> | ||
+ | <groupId>ch.qos.logback</groupId> | ||
+ | <artifactId>logback-classic</artifactId> | ||
+ | <version>${logback.version}</version> | ||
+ | </dependency> | ||
+ | </source> | ||
+ | |||
+ | |||
+ | {{DeprecatedSince| 7.0.0}} | ||
ZK uses [http://docs.oracle.com/javase/1.4.2/docs/guide/util/logging/overview.html the standard logger] to log messages. You could control what to log by configuring the logging of the Web server you are using. The configuration usually varies from one server to another. However, you could use the configuration mechanism provided by ZK as described in this section. It shall work with most Web servers. | ZK uses [http://docs.oracle.com/javase/1.4.2/docs/guide/util/logging/overview.html the standard logger] to log messages. You could control what to log by configuring the logging of the Web server you are using. The configuration usually varies from one server to another. However, you could use the configuration mechanism provided by ZK as described in this section. It shall work with most Web servers. | ||
Line 35: | Line 52: | ||
== Prepare a logging configuration file == | == Prepare a logging configuration file == | ||
− | + | {{DeprecatedSince| 7.0.0}} | |
A logging configuration file is a standard properties file. Each line is a key-value pair in the following format: | A logging configuration file is a standard properties file. Each line is a key-value pair in the following format: | ||
Line 56: | Line 73: | ||
=== Allowed Levels === | === Allowed Levels === | ||
− | + | {{DeprecatedSince|7.0.0}} | |
− | {| | + | {| class='wikitable' | width="100%" |
! <center>Level</center> | ! <center>Level</center> | ||
! <center>Description</center> | ! <center>Description</center> | ||
Line 82: | Line 99: | ||
=== Specify the handler for Jetty and servers that don't turn on the standard logger === | === Specify the handler for Jetty and servers that don't turn on the standard logger === | ||
− | + | {{DeprecatedSince|7.0.0}} | |
Some Web servers, such as Jetty, don't turn on the standard logger by default. Thus, in the logging configuration file, you have to configure the handler too. For example, you can turn on the <code>java.util.logging.ConsoleHandler</code> to write the logs to the console by adding the following lines to the logging configuration file: | Some Web servers, such as Jetty, don't turn on the standard logger by default. Thus, in the logging configuration file, you have to configure the handler too. For example, you can turn on the <code>java.util.logging.ConsoleHandler</code> to write the logs to the console by adding the following lines to the logging configuration file: | ||
Line 109: | Line 126: | ||
== Specify the configuration file in a library property == | == Specify the configuration file in a library property == | ||
− | + | {{DeprecatedSince|7.0.0}} | |
To let ZK load the logging configuration file, you have to specify in a library property called [[ZK Configuration Reference/zk.xml/The Library Properties/org.zkoss.util.logging.config.file|org.zkoss.util.logging.config.file]]. For example, | To let ZK load the logging configuration file, you have to specify in a library property called [[ZK Configuration Reference/zk.xml/The Library Properties/org.zkoss.util.logging.config.file|org.zkoss.util.logging.config.file]]. For example, | ||
Line 119: | Line 136: | ||
</source> | </source> | ||
− | If a relative path is specified, it will look for the | + | If a relative path is specified, it will look for the classpath first. If not found, it will assume it is related to the current directory, i.e., the directory specified in the system property called <code>user.dir</code>. |
You could specify an absolute path, such as <code>/usr/jetty/conf/zk-log.properties</code>, if you are not sure what the current directory is. | You could specify an absolute path, such as <code>/usr/jetty/conf/zk-log.properties</code>, if you are not sure what the current directory is. | ||
Line 126: | Line 143: | ||
= Disable All Logs = | = Disable All Logs = | ||
− | If you want to disable all loggers completely or change the level for all loggers, you don't need to prepare a logging configuration file. Rather, you can configure <javadoc>org.zkoss.zk.ui.http.DHtmlLayoutServlet</javadoc> in < | + | If you want to disable all loggers completely or change the level for all loggers, you don't need to prepare a logging configuration file. Rather, you can configure <javadoc>org.zkoss.zk.ui.http.DHtmlLayoutServlet</javadoc> in <code>WEB-INF/web.xml</code> as follows. |
<source lang="xml" > | <source lang="xml" > | ||
Line 144: | Line 161: | ||
Class: <javadoc>org.zkoss.util.logging.Log</javadoc> | Class: <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.logging.Logger</code>. However, we wrap it as <javadoc>org.zkoss.util.logging.Log</javadoc> to make it more efficient. |
<blockquote> | <blockquote> | ||
Line 162: | Line 179: | ||
} | } | ||
</source> | </source> | ||
− | + | ||
+ | = Reference = | ||
+ | * [https://logging.apache.org/log4j/2.x/security.html Apache Log4j Security Vulnerabilities] | ||
+ | |||
=Version History= | =Version History= | ||
− | + | ||
− | {| | + | {| class='wikitable' | width="100%" |
! Version !! Date !! Content | ! Version !! Date !! Content | ||
|- | |- |
Latest revision as of 09:41, 2 February 2024
In this section we describe how to configure the logging of ZK internal functions. You can generally ignore it, unless you'd like to know how ZK operates internally.
Notice that, if you are using Google App Engine, you can not configure the logging as described in this chapter. For more information, please refer to Setting up Google App Engine.
How to Configure Logging
Since 7.0.0
ZK uses SLF4J as its internal logging system, and developers can follow the SLF4J document to use the logging in ZK.
By default, ZK maven setting will bundle the slf4j-jdk14 implementation as its default logging.[1] If developers want to change that implementation for Log4j, Simple, or Logback, they have to exclude the dependency first like:
<dependency>
<groupId>org.zkoss.common</groupId>
<artifactId>zcommon</artifactId>
<version>${zk.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
Since 9.5.0
ZK maven dropped the transitive dependency of slf4j-jdk14. If a developer decides to enable logging, include either Log4j, Simple, or Logback implementation in their maven pom.xml file, e.g.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
Deprecated Since 7.0.0
ZK uses the standard logger to log messages. You could control what to log by configuring the logging of the Web server you are using. The configuration usually varies from one server to another. However, you could use the configuration mechanism provided by ZK as described in this section. It shall work with most Web servers.
There are basically two steps to configure the standard logger with ZK's configuration mechanism:
- Prepare a logging configuration file
- Specify the configuration file in a library property
Prepare a logging configuration file
Deprecated Since 7.0.0 A logging configuration file is a standard properties file. Each line is a key-value pair in the following format:
''a.package.or.a.class'' = ''level''
Here is an example of a configuration file.
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.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
Deprecated Since 7.0.0
Indicates no message at all. | |
SEVERE | Indicates providing error messages. |
Indicates providing warning messages. It also implies ERROR. | |
Indicates providing informational messages. It also implies ERROR and WARNING. | |
FINE | 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 |
Specify the handler for Jetty and servers that don't turn on the standard logger
Deprecated Since 7.0.0
Some Web servers, such as Jetty, don't turn on the standard logger by default. Thus, in the logging configuration file, you have to configure the handler too. For example, you can turn on the java.util.logging.ConsoleHandler
to write the logs to the console by adding the following lines to the logging configuration file:
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINER
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
Here is another example that configures the console and a file to be the target of the logs:
handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINER
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern = /var/log/jetty6/solr-%u.log
java.util.logging.FileHandler.level = FINER
org.zkoss.zk.ui.impl.UiEngineImpl=FINER
org.zkoss.bind=FINE
Specify the configuration file in a library property
Deprecated Since 7.0.0 To let ZK load the logging configuration file, you have to specify in a library property called org.zkoss.util.logging.config.file. For example,
<library-property>
<name>org.zkoss.util.logging.config.file</name>
<value>conf/zk-log.properties</value>
</library-property>
If a relative path is specified, it will look for the classpath first. If not found, it will assume it is related to the current directory, i.e., the directory specified in the system property called user.dir
.
You could specify an absolute path, such as /usr/jetty/conf/zk-log.properties
, if you are not sure what the current directory is.
Disable All Logs
If you want to disable all loggers completely or change the level for all loggers, you don't need to prepare a logging configuration file. Rather, you can configure DHtmlLayoutServlet in WEB-INF/web.xml
as follows.
<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>
For more information, please refer to ZK Configuration Reference.
How to Log
Class: Log
The logger used by ZK is based on the standard logger, java.util.logging.Logger
. However, we wrap it as Log to make it more efficient.
To log the message to the client rather than the console at the server, you could use Clients.log(String)
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);
}
}
Reference
Version History
Version | Date | Content |
---|---|---|
6.0.0 | February 2012 | LogService was deprecated. |