`

Logging in Tomcat

 
阅读更多

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:

  1. 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
  2. Download Log4J (v1.2 or later) and place the log4j jar in $CATALINA_HOME/common/lib.
  3. Download Commons Logging and place the commons-logging.jar (not commons-logging-api.jar) in $CATALINA_HOME/common/lib with the log4j jar.
  4. 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.

分享到:
评论

相关推荐

    Linux tomcat下catalina.out日志文件分割

    tomcat默认使用Java.util.logging记录日志,默认只记录tomcat的日志,不记录应用的日志。tomcat支持采用log4j进行日志记录,配置方法如下: 1.更新最新的tomcat_juli.jar包到./bin/目录下; 2.拷贝log4j.jar,lo4j....

    myEclipse6.5+Tomcat7 搭建环境

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory ``` 这个错误通常是因为Tomcat启动时找不到必要的类库。解决方法如下: 1. **确认JDK环境**: 确保正确设置了...

    Linux Tomcat 配置及加入服务,

    HOME -Djava.io.tmpdir=$TOMCAT_HOME/temp -Djava.util.logging.config.file=$TOMCAT_HOME/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina....

    ApacheTomcat整合入门级教程

    提供的文档资料如《ApacheTomcat整合教程.pdf》和《BOXIN网站系统环境搭建APACHE+TOMCAT.pdf》将更深入地指导你完成具体步骤。在学习过程中,遇到问题可参考官方文档或社区资源,不断积累经验,提高技术水平。

    tomcat日志详细说明

    Tomcat的日志配置可以通过编辑`conf/logging.properties`文件来实现。以下是一些关键配置示例: 1. **catalina.日期.log、localhost.日期.log** 日志配置: - 日志级别:`catalina.org.apache.juli.FileHandler....

    Apache Tomcat 7

    Configure logging for web applications deployed on Tomcat server Who this book is for This book is for those Web developers and/or Java programmers new to the open-source Apache Tomcat Web server. ...

    Linux下重新启动Tomcat的步骤详解

    本文主要介绍的是Linux下重新启动Tomcat的步骤,在Linux系统下,重启Tomcat使用命令操作的! 具体的步骤如下: ... 00:30:13 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat

    Linux下Tomcat重新启动

    在Linux系统下,重启Tomcat使用命令操作的!  首先,进入Tomcat下的bin目录  cd /usr/local/tomcat/bin  使用Tomcat关闭命令 ... 00:00:04 /opt/jdk1.6.0_37/bin/java -Djava.util.logging.config.file=/opt/t

    tomcat在linux中修改日志路径

    1. 修改catalina.sh 进入tomcat安装目录/bin,找到catalina.sh,并下载到本地,同时进行备份。 对本地的catalina.sh进行修改,将下图红框所示地方改...进入tomcat安装目录/conf/,找到logging.properties,并下载到本

    Tomcat使用Log4j输出catalina.out日志

    Tomcat默认的日志是用java.util.logging,有几点不足,文件catalian.out不能像log4j一样按天生成,将越来越大。日志格式和项目中用log4j打出来的不一致,不利于解析。 从tomcat官网...

    linux系统中修改tomcat默认输入日志路径的方法

    1、修改catalina.sh 进入tomcat安装目录/bin,找到...进入tomcat安装目录/conf/,找到logging.properties,先进行备份。 对本地的logging.properties进行修改,将所有的${catalina.base}/logs全部修改为/data/logs 3

    浅谈Tomcat乱码与端口占用的解决方案

    通常,在Tomcat的安装目录下的logs文件夹中,可以通过查看当天日期的日志文件,找到类似 Address already in use: bind 这样的错误信息,从而确定问题所在。一旦确定是哪个进程占用端口,可以通过任务管理器查找并...

    Windouws 64 位Tomcat7.0.40 + 64位jdk1.7.0u21 绿色版.part1

    │ │ logging.properties │ │ server.xml │ │ server.xml.bak │ │ tomcat-users.xml │ │ web.xml │ │ │ └─Catalina │ └─localhost ├─jdk1.7.0_21 │ │ COPYRIGHT │ │ LICENSE │ │ README....

    Linux下定时切割Tomcat日志并删除指定天数前的日志记录

    一般在部署Tomcat后,运行久了,catalina.out文件会越来越大,对系统的稳定造成了一定的影响。 1、可通过修改conf/logging.properties日志配置文件来屏蔽掉这部分的日志信息。 [root@localhost conf]# pwd /usr/...

    log4j配置[收集].pdf

    - WebLogic服务器默认提供了Commons Logging类包,这与其他服务器(如Tomcat)有所不同。 - 在WebLogic中使用Log4j需要对Commons Logging进行特定配置,以确保与Log4j兼容。 2. **Commons Logging配置** - **...

    conf.tar.gz

    9. **JARs in lib directory**:Tomcat的lib目录通常包含必要的库文件,如JDBC驱动,以便Tomcat可以连接到数据库。 备份“conf.tar.gz”可能是为了在更新、升级或出现问题时恢复原有的配置,确保Tomcat的稳定运行。...

    solr/ext/ 里面的jar包

    If using Jetty, the SLF4j logging jars need to go in the jetty lib/ext directory. For other containers, the corresponding directory should be used. For more information, see: ...

    jenkins持续集成单元测试和findbugs问题解决方案

    -- To use the plugin goals in your POM or parent POM --> <groupId>org.apache.maven.plugins <artifactId>maven-surefire-report-plugin <version>2.14.1 <groupId>org.apache.maven.plugins ...

    简单易用的日志系统

    本项目“简单易用的日志系统”是基于Tomcat服务器和SLF4J(Simple Logging Facade for Java)实现的,旨在为团队提供一个便捷的日志查看解决方案。 首先,让我们深入了解SLF4J。SLF4J是一个为各种日志框架提供一个...

Global site tag (gtag.js) - Google Analytics