<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="E:\TomcatService\apache-tomcat-6.0.41\webapps\CoolCustomSite" reloadable="true"></Context>
</Host>
Log4j代码:
log4j.rootLogger=info,R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.Encoding=UTF-8
log4j.appender.R.File=E\:/log/coolcustom.log
log4j.appender.R.DatePattern ='.'yyyy-MM-dd
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}]%-5p %c(line\:%L) %x-%m%n
如果没有配置上面的 <Context path="" /> 这个标签,可以按日期生成日志文件,但这样配置之后,每天都是覆盖上一天的日志文件,好是蛋疼啊
可是项目又需要去掉项目名访问,所以才有 <Context path="" /> 这个配置
请求大神有没有好的解决访问,既可以按日期生成日志文件,又可以不通过项目名访问程序
在线等...谢谢各位...
在CSDN搜了一下,这位兄弟跟我的需求是一样的,也没有找到解决方案
http://bbs.csdn.net/topics/390868230
可以参考他的描述
4 个解决方案
#2
在centos下没有这种情况发生,即使配置了虚拟目录,log4j也是正常按天分隔;但在windows下面,确实有该情况出现,我采用的办法是去掉虚拟目录,将默认访问网站的文件夹改为ROOT,则可以实现log4j正常分隔同时可以作为默认网站访问。
#3
有用
#4
我刚在我的centos7 的机器上试过,没有发生你说的问题,我修改系统日期后,日志正常归档common-default.log.2017-11-14.log
-rw-r--r-- 1 root root 90524 Nov 14 22:05 catalina.2017-11-14.log
-rw-r--r-- 1 root root 8995 Nov 15 00:00 catalina.2017-11-15.log
-rw-r--r-- 1 root root 732013 Nov 15 00:00 catalina.out
-rw-r--r-- 1 root root 225 Nov 15 00:00 common-default.log
-rw-r--r-- 1 root root 521592 Nov 14 22:05 common-default.log.2017-11-14.log
-rw-r--r-- 1 root root 88734 Nov 14 22:00 common-error.log
-rw-r--r-- 1 root root 0 Nov 14 21:41 host-manager.2017-11-14.log
-rw-r--r-- 1 root root 7578 Nov 14 22:05 localhost.2017-11-14.log
-rw-r--r-- 1 root root 2236 Nov 14 22:07 localhost_access_log.2017-11-14.txt
-rw-r--r-- 1 root root 2108 Nov 15 00:00 localhost_access_log.2017-11-15.txt
-rw-r--r-- 1 root root 0 Nov 14 21:41 logistics-component.log
-rw-r--r-- 1 root root 0 Nov 14 21:41 manager.2017-11-14.log
<appender name="DEFAULT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${pfms.log.home}/common-default.log" />
<param name="Append" value="true" />
<param name="encoding" value="GBK" />
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c{2} - %m%n" />
</layout>
</appender>
<!-- [错误日志APPENDER] -->
<appender name="ERROR-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${pfms.log.home}/common-error.log" />
<param name="Append" value="true" />
<param name="encoding" value="GBK" />
<param name="threshold" value="error" />
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c{2} - %m%n" />
</layout>
</appender>
<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="false">
<!--Temporary-->
<Context path="/" docBase="pfms.war" reloadable="true" debug="0" >
<Resource name="jdbc/oracle/pfms" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@*****************:****:****"
username="*********" password="********" maxActive="20" maxIdle="10"
maxWait="-1"/>
</Context>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
#1
#2
在centos下没有这种情况发生,即使配置了虚拟目录,log4j也是正常按天分隔;但在windows下面,确实有该情况出现,我采用的办法是去掉虚拟目录,将默认访问网站的文件夹改为ROOT,则可以实现log4j正常分隔同时可以作为默认网站访问。
#3
有用
#4
我刚在我的centos7 的机器上试过,没有发生你说的问题,我修改系统日期后,日志正常归档common-default.log.2017-11-14.log
-rw-r--r-- 1 root root 90524 Nov 14 22:05 catalina.2017-11-14.log
-rw-r--r-- 1 root root 8995 Nov 15 00:00 catalina.2017-11-15.log
-rw-r--r-- 1 root root 732013 Nov 15 00:00 catalina.out
-rw-r--r-- 1 root root 225 Nov 15 00:00 common-default.log
-rw-r--r-- 1 root root 521592 Nov 14 22:05 common-default.log.2017-11-14.log
-rw-r--r-- 1 root root 88734 Nov 14 22:00 common-error.log
-rw-r--r-- 1 root root 0 Nov 14 21:41 host-manager.2017-11-14.log
-rw-r--r-- 1 root root 7578 Nov 14 22:05 localhost.2017-11-14.log
-rw-r--r-- 1 root root 2236 Nov 14 22:07 localhost_access_log.2017-11-14.txt
-rw-r--r-- 1 root root 2108 Nov 15 00:00 localhost_access_log.2017-11-15.txt
-rw-r--r-- 1 root root 0 Nov 14 21:41 logistics-component.log
-rw-r--r-- 1 root root 0 Nov 14 21:41 manager.2017-11-14.log
<appender name="DEFAULT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${pfms.log.home}/common-default.log" />
<param name="Append" value="true" />
<param name="encoding" value="GBK" />
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c{2} - %m%n" />
</layout>
</appender>
<!-- [错误日志APPENDER] -->
<appender name="ERROR-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${pfms.log.home}/common-error.log" />
<param name="Append" value="true" />
<param name="encoding" value="GBK" />
<param name="threshold" value="error" />
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c{2} - %m%n" />
</layout>
</appender>
<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="false">
<!--Temporary-->
<Context path="/" docBase="pfms.war" reloadable="true" debug="0" >
<Resource name="jdbc/oracle/pfms" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@*****************:****:****"
username="*********" password="********" maxActive="20" maxIdle="10"
maxWait="-1"/>
</Context>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>