Tomcat Log System detailed

Source: Internet
Author: User

Details of the Tomcat log system

Synthesis: Tomcat-related log files
Cataline engine log file, file name Catalina. Date. Log
Tomcat under the internal code is thrown out of the log, file name localhost. date. log (JSP page internal Error exception, Org.apache.jasper.runtime.HttpJspBase.service class thrown, log information is in the file!) )
Tomcat under Default Manager application log, file name Manager. date. log
Console output log, linux default redirect to Catalina.out
Access log (Servlet.xml configuration)
The application redirects through Log4j.properties:${catalina.base}/logs/probe.log logs.
JULI:org.apache.juli.FileHandler the corresponding log file name: {prefix}. {Date}. {suffix} default Juli. date. Log

Tomcat under the Web application can use the following 3 kinds of logs:
Use the log java.util.logging provided by the JDK.
Use the log javax.servlet.ServletContext.log (...) defined in the Java servlets specification.
Use other log frameworks, such as log4j

The servlet logs used under different Web applications (or logs provided by the log framework) are independent of each other (this is related to Tomcat's class Loader, reference class Loader How-to
)。 If the Web application uses java.util.logging logs, then they are not independent of each other, because java.util.logging is loaded by bootstrap ClassLoader in the Java system, So it's shared across Web applications!

Log configuration file used by Tomcat: $CATALINA _base/conf/logging.properties
The Tomcat log management class uses the juli:logging_manager= "-djava.util.logging.manager=org.apache.juli.classloaderlogmanager" by default

Java's stdout and stderr are redirected to $catalina_base/logs/catalina.out, while: The following 2 types of error messages are also recorded here
uncaught exceptions printed by Java.lang.ThreadGroup.uncaughtException (..
Thread dumps, if you requested them via a system signal


Access log: It is related to the general log but not quite the same, it is configured in the context or host or engine in Servlet.xml. In the configuration section above, add the following value to the line, specific reference: the Valve Component
XML code
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"
Prefix= "Localhost_access_log." suffix= ". Logs" pattern= "common" resolvehosts= "false"/>


Tomcat uses the Juli log system by default (you can refer to the official website documentation to use log4j), which encapsulates the default JDK log java.util.logging and supports the same configuration as standard JDK logs. The biggest difference is that for different classloader, different profiles can be used so that different Web applications under Tomcat can use their own separate log files. In other words, the default log under Tomcat has the following 2 levels:
Global configuration file. That's usually done in the ${catalina.base}/conf/logging.properties file. The file is specified by the Java.util.logging.config.file System property which are set by the startup scripts. If It is not readable or isn't configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE.
Using Web-inf/classes/logging.properties in Web applications
Logging.properties in the default JRE will output the log to System.err (Consolehandler), while the default Tomcat configuration file conf/ Logging.properties will add multiple filehandlers to output the log to different files.

Juli the extended configuration of the log:
Prefix, which allows for a class that can be processed by multiple handler: A prefix may is added to handler names, so the multiple handlers of a single class might instantiated. A prefix is a String which starts with a digit, and ends with '. '. For example, 22foobar. is a valid prefix.
Refer to System variables, such as using ${catalina.base}/logs/prj.log to direct the log of the project PRJ to the logs directory under Tomcat: System property replacement was performed for Property values which contain ${systempropertyname}.
As in Java 6.0, loggers can define a list of handlers using the Loggername.handlers property.
By default, loggers won't delegate to their parent if they has associated handlers. This may is changed per logger using the Loggername.useparenthandlers property, which accepts a Boolean value.
Root Looger:the root logger can define its set of handlers using the. Handlers property.


Tomcat Juli Log format: Use Engine,host, context to define the log, engine is generally Catalina.
Org.apache.catalina.core.ContainerBase. [${engine}]. [${host}]. [${context}]
The default configuration file under Tomcat is ${catalina.base}/conf/logging.properties:
Java code
handlers = 1catalina.org.apache.juli.filehandler, 2localhost.org.apache.juli.filehandler, 3manager.org.apache.juli.filehandler, Java.util.logging.ConsoleHandler

. Handlers = 1catalina.org.apache.juli.filehandler, Java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# describes specific configuration info for handlers.
############################################################
# Cataline engine log file, file name Catalina. Date. Log
1catalina.org.apache.juli.filehandler.level = FINE
1catalina.org.apache.juli.filehandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.filehandler.prefix = Catalina.
# Tomcat under the internal code is thrown out of the log, file name localhost. date. log
2localhost.org.apache.juli.filehandler.level = FINE
2localhost.org.apache.juli.filehandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.filehandler.prefix = localhost.
# Tomcat under Default Manager application log, file name Manager. date. log
3manager.org.apache.juli.filehandler.level = FINE
3manager.org.apache.juli.filehandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.filehandler.prefix = Manager.
# console output log, linux default redirect to Catalina.out
Java.util.logging.ConsoleHandler.level = FINE
Java.util.logging.ConsoleHandler.formatter = Java.util.logging.SimpleFormatter


############################################################
# Facility specific properties.
# provides extra control for each logger.
############################################################

Org.apache.catalina.core.ContainerBase. [Catalina]. [Localhost].level = INFO
Org.apache.catalina.core.ContainerBase. [Catalina]. [Localhost].handlers = 2localhost.org.apache.juli.filehandler
# Wen Application/manager log
Org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/manager].level = INFO
Org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/manager].handlers = 3manager.org.apache.juli.filehandler
# Wen Application/host-manager log
Org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/host-manager].level = INFO
Org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/host-manager].handlers = 4host-manager.org.apache.juli.filehandler

# For example, set the Com.xyz.foo logger to only log SEVERE
# messages:
#org. Apache.catalina.startup.ContextConfig.level = FINE
#org. Apache.catalina.startup.HostConfig.level = FINE
#org. Apache.catalina.session.ManagerBase.level = FINE
#org. Apache.catalina.core.aprlifecyclelistener.level=fine

Tomcat Log System detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.