赞
踩
Hello,I'm Shendi
目录
2.Download Log4J (Tomcat requires v1.2.x).
4.If you want to configure Tomcat to use log4j globally:
当我在Eclipse里编写好web程序后,直接在文件系统中启动Tomcat,发现没有错误日志输出了
但是在Eclipse中启动会有日志输出
直接使用命令行的方式跑catalina.bat 也没有作用
通过查阅,发现高版本Tomcat默认是不带控制台日志输出的
解决办法就是将默认日志输出替换为 log4j
官网文档,可进入官网自行查看
http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j
log4j.properties
with the following content and save it into $CATALINA_BASE/lib
创建log4.properties到Tomcat的lib目录下
默认内容如下
- log4j.rootLogger = INFO, CATALINA
-
- # Define all the appenders
- log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
- log4j.appender.CATALINA.File = ${catalina.base}/logs/catalina
- log4j.appender.CATALINA.Append = true
- log4j.appender.CATALINA.Encoding = UTF-8
- # Roll-over the log once per day
- log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd'.log'
- log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
- log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
-
- log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
- log4j.appender.LOCALHOST.File = ${catalina.base}/logs/localhost
- log4j.appender.LOCALHOST.Append = true
- log4j.appender.LOCALHOST.Encoding = UTF-8
- log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd'.log'
- log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
- log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
-
- log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
- log4j.appender.MANAGER.File = ${catalina.base}/logs/manager
- log4j.appender.MANAGER.Append = true
- log4j.appender.MANAGER.Encoding = UTF-8
- log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
- log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
- log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
-
- log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
- log4j.appender.HOST-MANAGER.File = ${catalina.base}/logs/host-manager
- log4j.appender.HOST-MANAGER.Append = true
- log4j.appender.HOST-MANAGER.Encoding = UTF-8
- log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
- log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
- log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
-
- log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
- log4j.appender.CONSOLE.Encoding = UTF-8
- log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
- log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
-
- # Configure which loggers log to which appenders
- log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
- log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
- INFO, MANAGER
- log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
- INFO, HOST-MANAGER
下载log4j,版本最低为1.2
这是官网提供的链接 http://logging.apache.org/log4j
也可以直接通过此链接下载
http://archive.apache.org/dist/logging/log4j/1.2.17/
tomcat-juli.jar
and tomcat-juli-adapters.jar
that are available as an "extras" component for Tomcat.下载 tomcat-juli.jar 和 tomcat-juli-adapters.jar
官网链接 http://tomcat.apache.org/tomcat-7.0-doc/extras.html
可以在 http://tomcat.apache.org/download-70.cgi 下找到extras 里找到对应jar
这里直接提供地址了,不确定你是否需要的是这个版本
tomcat-juli
https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-7/v7.0.107/bin/extras/tomcat-juli.jar
tomcat-juli-adapters
https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-7/v7.0.107/bin/extras/tomcat-juli-adapters.jar
配置Tomcat全局使用log4j
log4j.jar
and tomcat-juli-adapters.jar
from "extras" into $CATALINA_HOME/lib
.$CATALINA_HOME/bin/tomcat-juli.jar
with tomcat-juli.jar
from "extras".将log4j和tomcat-juli-adapters放到Tomcat的lib目录下
将tomcat-juli.jar放入Tomcat的bin目录下,如果有,直接替换
这一部分没啥好说的,一般都不设置自己的目录,所以我就直接用翻译软件复制过来了
如果您使用单独的$ CATALINA_HOME和$ CATALINA_BASE运行Tomcat,并且希望配置为仅在单个$ CATALINA_BASE中使用log4j:
$CATALINA_BASE/bin
和 $CATALINA_BASE/lib
目录(如果不存在)。log4j.jar
与 tomcat-juli-adapters.jar
从“临时演员”成 $CATALINA_BASE/lib
tomcat-juli.jar
从“ extras” 放入$CATALINA_BASE/bin/tomcat-juli.jar
$CATALINA_BASE/conf/catalina.policy
文件以将其调整为使用tomcat-juli.jar的其他副本。
$CATALINA_BASE/conf/logging.properties
to prevent java.util.logging generating zero length log files.删除conf下的loggin.properties文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。