如何旋转tomcat localhost日志? [英] How to rotate the tomcat localhost log?

查看:122
本文介绍了如何旋转tomcat localhost日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux系统中使用tomcat 6x.它每天打印一次本地日志文件,例如localhost.2011-06-07localhost.2011-06-08.我想在达到1MB时旋转localhost.

I am using tomcat 6x in a Linux system. It prints a localhost log file like localhost.2011-06-07, localhost.2011-06-08 on a daily basis. I want to rotate the localhost when it reaches 1MB.

我可以为我的Web应用程序旋转log4j中的日志文件.但是这个tomcat的localhost日志文件,我无法使其旋转.除了使用logrotate以外,还有其他解决方案吗?

I can rotate log files in log4j for my web apps. But this localhost log file of tomcat, I couldn't get it to rotate. Has any got a solution other than using logrotate?

推荐答案

您是否想要使用logrotate,还是您的系统管理员不允许您这样做?

Do you not want to use logrotate, or does your sys admin not allow you to?

鉴于这种限制,我担心(根据我从

Given that restriction, I'm afraid (from what I have been able to learn from the documentation) that there is no automatic way to do what you want (rotate log files based on the size alone).

如果您只想停止Tomcat每天默认创建新日志的默认行为(我发现这对开发环境或低流量站点非常烦人),则可以通过更改访问日志"Valve"的 fileDateFormat 属性,该属性在Ubuntu Server上是在/etc/tomcat7/server.xml 中定义的.对于Tomcat 6,它可能位于类似的位置.

If you merely want to stop Tomcat's default behavior of creating a new log every day (which I find extremely annoying for a development environment or low-traffic site), you can certainly do this by changing the fileDateFormat property of the Access Log "Valve", which on Ubuntu Server is defined in /etc/tomcat7/server.xml. It's probably in a similar location for Tomcat 6.

由于您提到了严格的sys admin,所以我认为此服务器不受您的控制,因此该路径无关紧要.如果您确实有能力修改Tomcat的日志配置,那么希望您知道在哪里可以找到合适的文件.

Since you mention a restrictive sys admin, I gather that this server is not under your control, so that path is irrelevant. If you do have the ability to modify Tomcat's log configuration, hopefully you know where to find the appropriate file.

在该.xml文件中,在为相应主机配置"Catalina"引擎的部分中,将 className 设置为"org.apache.catalina.valves.AccessLogValve"的Valve实体查找为您的网站(在我的情况下为localhost).尽管Tomcat 6文档没有提及它,但是可以推断出默认的fileDateFormat为"yyyy-MM-dd".将日期包括在日志文件名中会告诉Tomcat(通过暗示)您也希望日志每天都旋转.如果您希望它每月轮换一次,例如,只需将fileDateFormat更改为"yyyy-MM".

In that .xml file, look for the Valve entity with className set to "org.apache.catalina.valves.AccessLogValve" in the section which configures the "Catalina" Engine for the appropriate host for your site (localhost in my case). Although the Tomcat 6 documentation doesn't mention it, one can deduce that the default fileDateFormat is "yyyy-MM-dd". Including the day in the log filename tells Tomcat (by implication) that you also want the log rotated every day. If you wanted it to be rotated, say, only once a month, just change the fileDateFormat to "yyyy-MM".

在我的服务器上,默认的Logging Valve定义是:

On my server, the default Logging Valve definition was this:

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

要将其更改为每月日志轮换,我只需添加适当的fileDateFormat属性:

To change this to monthly log rotation, I would just add the appropriate fileDateFormat attribute:

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           fileDateFormat="yyyy-MM" prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

由于我能够(并愿意)使用logrotate,所以我已完全关闭了Tomcat的内置日志轮换和基于日期的文件命名,并且只要日志达到1MB,就只需使用logrotate来轮换日志.

Since I am able (and willing) to use logrotate, I have turned off Tomcat's built-in log rotation and date-based file naming completely, and simply use logrotate to rotate the logs whenever the log reaches 1MB.

编辑要回答dgrant的问题,将更改更改为/etc/tomcat7/server.xml,而我正在使用的实际阀门配置是这样的:

Edit To answer dgrant's question, the changes were to /etc/tomcat7/server.xml, and the actual valve configuration I'm using is this:

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       pattern="combined" rotatable="false"
       prefix="access_log" />

请注意,组合"模式与原始配置中的显式模式定义等效(至少对于Tomcat 7).如果您想了解更多,所有这些内容都可以在我的原始文档链接中找到.只需在rotatable属性上查找该部分即可.

Note that the 'combined' pattern is equivalent (at least for Tomcat 7) to the explicit pattern definition in the original configuration. All this is well-covered in my original documentation link if you want to read more. Just look for the section on the rotatable attribute.

这篇关于如何旋转tomcat localhost日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆