tomcat使用log4j管理日志
1、JDK+tomcat环境 参考:http://www.cnblogs.com/zzzhfo/p/6444029.html
2、下载相关软件
log4j下载地址
http://www.apache.org/dist/logging/log4j/
http://www.apache.org/dist/logging/log4j/1.2.17/
http://www.apache.org/dist/logging/log4j/1.2.17/log4j-1.2.17.tar.gz
3、停止服务
shutdown.sh
- 将log4j.properties和log4j-1.2.17.jar放到tomcat/lib目录下
配置log4j.properties
这里方便测试
'.'yyyy-MM-dd-HH-mm'.log'设置为每分钟
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-
# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd-HH-mm'.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-
log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd-HH-mm'.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-
log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd-HH-mm'.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-
log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd-HH-mm'.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-
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
到官网下载 tomcat-juli.jar和tomcat-juli-adapters.jar包。
https://tomcat.apache.org/
https://tomcat.apache.org/download-70.cgi
http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.77/bin/extras/tomcat-juli-adapters.jar
http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.77/bin/extras/tomcat-juli.jar
- 将tomcat-juli-adapters.jar包放到tomcat/lib目录下
- 将tomcat-juli.jar包放到tomcat/bin目录下(替换原有的)
- 删除或重命名tomcat/conf目录下的logging.properties文件
- 修改tomcat/conf/目录下context.xml
将<Context>改为<Context swallowOutput="true">
[root@localhost conf]# cat context.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application --> <!--<Context swallowOutput="true"> --> <Context swallowOutput="true"> <!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- <Context swallowOutput="true"> -->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
--> </Context>
- 启动服务
[root@localhost tomcat]# bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1..0_79
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
查看日志
首先要访问自己的工程,让其产生日志。
[root@localhost logs]# ls
catalina.----.log catalina.out.----.log catalina.out.----.log localhost localhost.log.----.log
catalina.out catalina.out.----.log catalina.out.----.log localhost.----.log localhost.log.----.log
catalina.out.----.log catalina.out.----.log catalina.out.----.log localhost.----.log localhost.log.---.log
catalina.out.----.log catalina.out.----.log localhost.----.log localhost.log.---.log
catalina.out.----.log catalina.out.----.log localhost_access_log.--.txt manager
catalina.out.----.log catalina.out.----.log host-manager localhost_access_log.--.txt manager.log
catalina.out.---.log catalina.out.----.log host-manager.log localhost.log
catalina.out.----.log catalina.out.----.log localhost.log.----.log
参考资料:http://www.open-open.com/doc/list/134
tomcat使用log4j管理日志的更多相关文章
- tomcat配置使用log4j管理日志
从tomcat官网下载和tomcat对应的tomcat-juli.jar和tomcat-juli-adapters.jar,从log4j官网下载log4j的jar包(我用的是log4j-1.2.17. ...
- tomcat 使用log4j进行日志切割
因为tomcat catalina.out日志不会自己主动切割, 一.日志切割所需包在附近中 1. 压缩包中有三个jar包: log4j-1.2.16.jar tomcat-juli ...
- 成功配置TOMCAT的LOG4J日志系统,格式:HTML+每天以YYYY-MM-DD.LOG命名的日志文件
关于log4j.properties文件在web项目中放的位置,找过很多,最后实践结果是: 一.web项目 二.放在src的目录里面,然后项目生成后会自动在\WEB-INF\classes文件里有份l ...
- kettle使用log4j管理输出日志
在使用kettle进行数据分析和清洗时日志非常多而且杂乱,使用原有的日志有时找不到异常的位置,有时日志不够详细,说简单一点就是日志不是我们想要的.因而对kettle日志进行相应的管理就想得尤为重要了. ...
- 解决tomcat下面部署多个项目log4j的日志输出会集中输出到一个项目中的问题
在一次项目上线后,发现了一个奇怪的问题,经过对源码的阅读调试终于解决,具体经过是这样的: 问题描述:tomcat7下面部署多个项目,log4j的日志输出会集中输出到一个项目中,就算配置了日志文件的绝对 ...
- Spring Boot 整合 slf4j+log4j 实现日志管理
一:首先新建一个jar项目,如下图: 二:添加log4j的依赖,如下pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0 ...
- 用slf4j统一管理日志总结
用slf4j统一管理日志总结 参考网页:http://www.slf4j.org/ 一.使用slf4j统一管理并配置统一使用log4j日志 使用的jar:(slf4j-api-1.7.5.jar,jc ...
- log4j.properties 日志文件的详细配置说明
一.在一个web 项目中,使用tomcat 启动通常会在控制台输出出现一个警告信息: 通常为未添加 log4j.properties文件的原因. 二.下面以一个普通的maven项目为例说明一下 1. ...
- tomcat的catalina.out日志文件过大
今天发现一个服务器的/opt目录数据过大,最后发现是tomcat中的catalina.out日志过大引起的 用du命令查看opt下一层的数据文件大小 [root@ccssapportalp opt]# ...
随机推荐
- 【译】GNU Radio How to write a block 【如何开发用户模块及编写功能块】
本文讲解如何在GNU Radio中添加用户开发的信号处理模块,译文如有不当之处可参考原文地址:http://gnuradio.microembedded.com/outoftreemodules Ou ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料汇总 (上)
转载:http://dataunion.org/8463.html?utm_source=tuicool&utm_medium=referral <Brief History of Ma ...
- rapidjson的read和write的sample
头文件 #include "json/document.h" #include "json/prettywriter.h" #include "jso ...
- 【CSS】文字超出显示省略号&连续字符换行
方法1.多行控制(css3) .text { width: 100%; word-break: break-all; display: -webkit-box; -webkit-line-clamp: ...
- rtmp直播推流(一)--flv格式解析与封装
flv文件格式分析,可参看RTMP中FLV流到标准h264.aac的转换,该文章写的很清晰. flv封装格式解析,可参看视音频数据处理入门:FLV封装格式解析,文章图文并貌,很直观. flv文件封装, ...
- java代码------计算器核心位置添加
总结:点击等号时,什么代码 else if(str.equals("-")){ ready=true; if(c=='\0'){ num1=Double.parseDouble(j ...
- error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
编译出现如下错误: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such ...
- 深入 innodb
深入innodbInnoDB表为IOT,采用了B+树类型,故每个页面至少要存储2行数据,如果行过大则会产生行溢出:理论上InnoDB表中varchar可存储65535字节,但对于InnoDB其实际上限 ...
- mongodb一些语法
一.DB shell数据操作 shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的. Ø 数据库 1.Help查看命令提示 help ...
- python学习(二十三) String(下) 分片和索引
分片: 记住, 是开闭区间. a = "abcdef"print(a[:])print(a[1:])print(a[:3])print(a[-2])print(a[:-2])pri ...