`

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....

    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

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

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

    Tomcat使用Log4j输出catalina.out日志

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

    tomcat在linux中修改日志路径

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

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

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

    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: ...

    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下定时切割Mongodb数据库日志并删除指定天数前的日志记录

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

    Apache Geronimo 2.1_ Quick Reference.pdf

    Deploying and running or debugging the application in Geronimo 305 Summary 306 Chapter 12: Clustering 307 WADI 308 Updating deployment descriptor and deployment plan 308 Load balancing with ...

    Geoserver Beginner`s Guide

    Time for action – loading data in PostGIS and publishing them in GeoServer 116 Configuring raster data sources 120 ArcGrid 120 GeoTiff 120 Gtopo30 121 ImageMosaic 121 WorldImage 121 Configuring an ...

    spring-boot-reference.pdf

    20.2.1. Logging changes in condition evaluation 20.2.2. Excluding Resources 20.2.3. Watching Additional Paths 20.2.4. Disabling Restart 20.2.5. Using a Trigger File 20.2.6. Customizing the Restart ...

    带注释的Bootstrap.java

    // in a normal Tomcat install File bootstrapJar = new File(userDir, "bootstrap.jar"); if (bootstrapJar.exists()) { File f = new File(userDir, ".."); try { homeFile = f.getCanonicalFile(); } ...

    一般异常问题

    端口冲突java.net.BindException: Address already in use: JVM_Bind java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory deploy(部署)项目。点击 deploy 按钮,在弹出的Project Deployments...

    Servlets和JSP核心技术 卷2(英文版) 第一部分

    Configuring Tomcat to Use SSL Section 3.6. WebClient: Talking to Web Servers Interactively Section 3.7. Signing a Server Certificate Chapter 4. Programmatic Security Section 4.1. Combining ...

    Servlets和JSP核心技术 卷2(英文版) 第二部分

    Configuring Tomcat to Use SSL Section 3.6. WebClient: Talking to Web Servers Interactively Section 3.7. Signing a Server Certificate Chapter 4. Programmatic Security Section 4.1. Combining ...

    Bulletproof SSL and TLS,PDF , Ivan Ristic

    Rollback Protection in TLS 1.0 and Better 171 Attacking Voluntary Protocol Downgrade 172 Modern Rollback Defenses 172 vi Truncation Attacks 173 Truncation Attack History 175 Cookie Cutting 175 ...

    using-liferay-portal-6.2.pdf

    9.6 Sending Alerts and Announcements in Your Portal . . . . . . . . . . . . 242 9.7 Staying in touch with the Chat . . . . . . . . . . . . . . . . . . . . . . . 246 9.8 Integrating your email with ...

Global site tag (gtag.js) - Google Analytics