Logrotate helps to manage your log files. It can periodically read, minimize, back up, creates new log files, and basically anything you may ever want to do with them. This is usually used to to help prevent any single log file from getting unwieldy in size. It is commonly also used to delete old log files so as not to fill your server's hard drive.
Many apps setup Logrotate for you. For instance, installing Apache in Ubuntu adds the file /etc/logrotate.d/apache2
, which is a configuration files used by Logrotate to rotate all apache access and error logs.
Configuring Logrotate
In stock Ubuntu, any config file you put into /etc/logrotate.d
is going to run once per day. Logs are typically rotated once per day or less (Apache default in Ubuntu is in fact weekly).
Default Apache
Let's look over Apache's default in Ubuntu - /etc/logrotate.d/apache2
.
http://linuxcommand.org/man_pages/logrotate8.html
关于日志的一般设置 日志过滤
ErrorLog "|/opt/xxx/install/cronolog/sbin/cronolog /home/admin/yyy/logs/cronolog/%Y/%m/%Y-%m-%d-error_log" LogLevel warn LogFormat "%h %D %{X_READTIME}i %t \"%m http://%V%U%q\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog SetEnvIf Request_URI "^/robots\.txt$" dontlog SetEnvIf Request_URI "\.swf$" dontlog SetEnvIf Request_URI "\.gif$" dontlog SetEnvIf Request_URI "\.jpg$" dontlog SetEnvIf Request_URI "\.ico$" dontlog SetEnvIf Request_URI "\.jpeg$" dontlog SetEnvIf Request_URI "\.bmp$" dontlog SetEnvIf Request_URI "\.png$" dontlog SetEnvIf Request_URI "\.js$" dontlog SetEnvIf Request_URI "\.css$" dontlog SetEnvIf Request_URI "\.wav$" dontlog SetEnvIf Request_URI "\.swf$" dontlog SetEnvIf Request_URI "home/css" dontlog SetEnvIf Request_URI "/auction/auto/*" dontlog SetEnvIf Request_URI "/auction/associate_categories.htm*" dontlog SetEnvIf Request_URI "/auction/latest_visit.htm*" dontlog CustomLog "|/opt/xxx/install/cronolog/sbin/cronolog /home/admin/cai/logs/cronolog/%Y/%m/%Y-%m-%d-xxx-access_log" combined env=!dontlog

Tomcat 为每个web app 产生一个 access log file
方法:添加一个文件
位置:tomcat7/webapps/web_name/META-INF
文件名:context.xml
文件内容:
<?xml version='1.0' encoding='utf-8'?> <Context path="/precheck"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log_test." suffix=".txt" pattern="combined" fileDateFormat="yyyy-MM-dd" resolveHosts="false" /> </Context>