Logging in Tomcat
print-friendly
version
Introduction
Tomcat 5.5 uses Commons Logging throughout its internal code allowing the developer to choose a logging configuration that suits their needs, e.g java.util.logging or Log4J. Commons Logging provides Tomcat the ability to log hierarchially across various log levels without needing to rely on a particular logging implementation.
An important consequence for Tomcat 5.5 is that the <Logger> element found in previous versions to create a localhost_log is no longer a valid nested element of <Context>. Instead, the default Tomcat configuration will use java.util.logging. If the developer wishes to collect detailed internal Tomcat logging (i.e what is happening within the Tomcat engine), then they should configure a logging system such as java.util.logging or log4j as detailed next.
log4j
Tomcat 5.5 has done away with localhost_log which you may be familiar with as the runtime exception/stack trace log. These types of error are usually thrown by uncaught exceptions, but are still valuable to the developer. They can now be found in the stdout log.
If you need to setup cross-context detailed logging from within Tomcat's code, then you can use a simple log4j configuration. Note that this logging van be very verbose depending on the log level you chose to use. Note also that a log4j logging configuration is not going to produce stack trace type logging: those stack traces are output to stdout as discussed above.
Follow the following steps to setup a file named tomcat.log that has internal Tomcat logging output to it:
Create a file called log4j.properties with the following content and save it into common/classes.
log4j.rootLogger=debug, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/tomcat.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.logger.org.apache.catalina=DEBUG, R
Download Log4J (v1.2 or later) and place the log4j jar in $CATALINA_HOME/common/lib.
Download Commons Logging and place the commons-logging.jar (not commons-logging-api.jar) in $CATALINA_HOME/common/lib with the log4j jar.
Start Tomcat
This log4j configuration sets up a file called tomcat.log in your Tomcat logs folder with a maximum file size of 10MB and up to 10 backups. DEBUG level is specified which will result in the most verbose output from Tomcat.
You can (and should) be more picky about which packages to include in the logging. Tomcat 5.5 uses defines loggers by Engine and Host names. For example, for a default Catalina localhost log, add this to the end of the log4j.properties above. Note that there are known issues with using this naming convention (with square brackets) in log4j XML based configuration files, so we recommend you use a properties file as described until a future version of log4j allows this convention.
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R
log4j.logger.org.apache.catalina.core=DEBUG, R
log4j.logger.org.apache.catalina.session=DEBUG, R
Be warned a level of DEBUG will produce megabytes of logging and slow startup of Tomcat. This level should be used sparingly when debugging of internal Tomcat operations is required.
Your web applications should certainly use their own log4j configuration. This is valid with the above configuration. You would place a similar log4j.properties file in your web application's WEB-INF/classes folder, and log4j1.2.8.jar into WEB-INF/lib. Then specify your package level logging. This is a basic setup of log4j which does *not* require Commons-Logging, and you should consult the log4j documentation for more options. This page is intended only as a bootstrapping guide.
我用的依然是Log 4J,几点建议就是:
1
log4j.rootLogger=debug, R
log4j.logger.org.apache.catalina=DEBUG, R
中的debug, DEBUG根据你的记录级别调整,我喜欢用error ERROR
2
log4j.appender.R.File=${catalina.home}/logs/tomcat.log
这个地方不需要人为修改
3
建议在系统环境变量增加:CATALINA_HOME一项配置以下Tomcat的安装目录
另外一篇:
习惯用log4j来配置log信息的输出。
新建log4j.properties,内容为
log4j.rootLogger=info,Console,R
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
#log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.Console.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss} %5p %c{1}:%L - %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/tomcat.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy.MM.dd HH:mm:ss} %5p %c{1}(%L): %m%n
log4j.logger.org.apache=info, R
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R
log4j.logger.org.apache.catalina.core=info, R
log4j.logger.org.apache.catalina.session=info, R
最后四行是tomcat的信息,如果改为debug日志文件将十分庞大。
将这个文件放入${catalina.home}/common/classes下,再将log4j.jar和commons-logging.jar放入${catalina.home}/common/lib下,就可以在${catalina.home}/logs/下见到日志了。
分享到:
相关推荐
《严蔚敏数据结构与算法实现:Loser Tree解析》 在计算机科学中,数据结构与算法是核心的基础,它们是解决复杂问题的关键工具。严蔚敏教授的教材以其深入浅出的讲解和丰富的实例著称,对于学习者来说是一份宝贵的...
《严蔚敏数据结构与算法实现:Loser Tree解析》 在计算机科学中,数据结构与算法是构建高效软件的基础,而严蔚敏教授的教材《数据结构》因其深入浅出的讲解,一直以来都是该领域的重要参考书。本篇文章将重点解析...
(6条消息)VMware15 + Ubuntu18.04安装_Elio_LosEr的博客-CSDN博客.html
8. 社会接受度与变革:韩寒的成功挑战了社会对“winner”和“loser”的刻板印象,推动了社会对多元化才能和非传统成功路径的接纳和理解。 总结:韩寒的故事揭示了教育体制的局限性,提倡对个体差异的尊重和多元化...
【标题】和【描述】中提到的“初中语文文摘历史爱情loser蔡琴”似乎是一个故事,讲述了蔡琴在经历人生低谷时如何通过朋友们的帮助重新找回自信的故事。这个故事的核心知识点是关于个人优势和成功的关系,以及如何...
OPAAA LOSER机器人 :crocodile: 费拉门塔斯 > Termux > WhatsApp > 2 Celulares 在上获取BarBarKey 安装 Siga os passos abaixo! > termux-setup-storage (depois disso toque na permissão) > apt install git >...
IDA Pro mn103处理器模块源码
语言:English 假新闻以您的方式 如果您讨厌您的新闻提要,并且希望它可以得到解决,那么此扩展名适合您。 您可以选择自己讨厌的独裁者,每当他们的名字出现在页面上时,它将更改为您想要的任何名称。...
【Loser Tree in C++】 Loser Tree,也称为最小堆树或败者树,是一种数据结构,主要用于高效地维护一组动态最小值。在计算机科学中,它常用于实现快速的优先队列,特别是在最坏情况下需要保持低时间复杂度的操作,...
cd loser # If you have a bash environment, ./gradlew :desktop:run # On windows, gradlew.bat :desktop:run 视频 游戏演示视频: 游戏内控制台演示视频: 执照 所有软件代码均在下获得许可。 所有艺术资产均...
根据给定的信息,本文将对严蔚敏版《数据结构》中的相关知识点进行详细解析,主要涉及基于loser树实现的K路归并算法。 ### 一、严蔚敏《数据结构》简介 严蔚敏教授编著的《数据结构》是国内计算机专业非常经典的...
The player who remove the last stick is the loser. The opponent remove sticks at the first, then it's your turn. Write a program to determine how many sticks should be removed when there's n sticks ...
"Biggest Loser"是一个健身目标追踪器应用,它的命名可能源自流行的电视节目,该节目激励参与者通过健康饮食和锻炼来实现体重减轻的目标。在这个项目中,我们将关注它如何使用JavaScript这一编程语言来实现功能。 ...
失败者(学习操作策略选举机器人) 星际争霸2 AI提案与报告设置此设置假定您使用的计算机运行的是Linux操作系统,并且运行的是python 3.5+设置Starcraft 2无头环境转到并按照其有关安装protobuf环境的说明进行操作。...
在本例中,我们关注的是一个名为"loser-0.0.2.tar.gz"的压缩包,它可以从PyPI官网上下载。 "loser-0.0.2.tar.gz"是一个源码发布的版本,通常包含Python项目的所有源代码、文档、配置文件等。".tar.gz"是Unix/Linux...
Loser-s-Economics-and-works-of-neo-anderson You know, I know [ { "tips": "该文件的功能为 时间范围、中断下载等功能做准备,现在暂时用不到,您可以随时删除该文件", "totla": 10, "list": [ { "comm_msg_info":...
最大的输家利用最大的输家。 如果您在 DSi 或 3DS 系统上使用真实卡带,则在 DSi 模式下运行,否则,它将在 DS 模式下运行。 支持美国和欧盟地区。 阅读更多。
HP loser jetM1005打印机的驱动程序
”这是一道关于恐惧心理的题目,答案可能是“L”,因为它代表了“Loser”(失败者)。 5. “What clothing is always sad?”这题的答案是“Blue Jeans”,因为blue在英文中也有忧郁、悲伤的意思,同时Blue Jeans...
例如,句子"The loser closely enclosed himself in the closet"中的"loser"和"enclosed"可以帮助理解失败者的心态,而"The composer was proposed to decompose his composition into components"则将音乐创作与...