By default Tomcat appends the date to log files e.g., localhost.2010-12-22.log and same with the catalina log. I don't want the date in the log file and I can't seem to find how to remove it. The logging documentation doesn't say anything 开发者_StackOverflow中文版about the date pattern. Any ideas are greatly appreciated.
http://tomcat.apache.org/tomcat-6.0-doc/logging.html
None of the other answers helped me much, though Thomas's was closest. The documentation I found was:
- http://tomcat.apache.org/tomcat-6.0-doc/logging.html
- http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/juli/FileHandler.html
So I added the following to Tomcat's logging.properties
file. This removes the date from the localhost logs, and the other three log types that Tomcat dates by default:
1catalina.org.apache.juli.FileHandler.rotatable = false
2localhost.org.apache.juli.FileHandler.rotatable = false
3manager.org.apache.juli.FileHandler.rotatable = false
4host-manager.org.apache.juli.FileHandler.rotatable = false
#
# default is true, which causes a date to be added to the filename
1catalina.org.apache.juli.FileHandler.suffix = log
2localhost.org.apache.juli.FileHandler.suffix = log
3manager.org.apache.juli.FileHandler.suffix = log
4host-manager.org.apache.juli.FileHandler.suffix = log
#
# default is .log, but without date, the extra dot is not needed
de_simakov's answer was correct for the most part - but it had a one letter typo. Find a configuration similar to this in conf/server.xml
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="http_access" suffix="log" pattern="common"
rotatable="false" resolveHosts="false" />
Notice the rotatable="false" attribute.
The documentation you link to is for logging within your application, not for logging by the Tomcat server itself. As mentioned in another answer, the appropriate documentation is here. On an Ubuntu Server system, you'll want to change the settings in /etc/tomcat7/server.xml. This file may be in another location on your system.
A configuration similar to this will prevent Tomcat from putting the date in the log file name -- but it will also prevent your access log from ever being rotated by Tomcat, which is probably a bad idea unless you set up an appropriate logrotate configuration for the server.
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="http_access" suffix="log" pattern="common"
rotateable="false" resolveHosts="false" />
This should be easy on Tomcat 7: see this docs
renameOnRotate attribute
By default for a rotatable log the active access log file name will contain the current timestamp in fileDateFormat. During rotation the file is closed and a new file with the next timestamp in the name is created and used. When setting renameOnRotate to true, the timestamp is no longer part of the active log file name. Only during rotation the file is closed and then renamed to include the timestamp. This is similar to the behavior of most log frameworks when doing time based rotation. Default value: false
The magic property for the default JULI logging in Tomcat is "rotatable". Usually there are two places where logging is defined in default installations: logging.properties and the server configurations (server.xml).
For the logging.properties you should use this: 1catalina.org.apache.juli.FileHandler.rotatable = false
For the server configuration it would look like this:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory=" prefix="access_log" suffix=".txt" rotatable="false" pattern="%h %l %u %t "%r" %s %b" />
Please look here for further details:
http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Log_Valve
The more appropriate answer to your direct question is the boolean "renameOnRotate". The assumption is that you want daily logging, but do not want the timestamp. This will name the file based on prefix/suffix, and append the timestamp to the log file after the log file has been rotated:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access" suffix=".log" renameOnRotate="true"
pattern="%a %A %h %H %l %m %t %u %U "%r" %s %b " resolveHosts="false" />
Tomcat's logging is governed by the <Valve>
config elements, usually in server.xml
or context.xml
. These allow you to control things like the data suffix.
Here's the docs for the access log value, which I assume is what you mean by localhost.2010-12-22.log
. Not sure about catalina.out
, but that must use a similar mechanism.
I know this is old, but for a complete example using logrotate.d, remember to replace with your tomcat version. You have to edit both, server.xml and logging.properties then edit/create a logrotate config. Also, your path to the config files might be different.
logrotate config:
vi /etc/logrotate.d/tomcat<version>
/var/log/tomcat<version>/catalina.out
{
daily
rotate 12
compress
copytruncate
create 640 tomcat adm
}
/var/log/tomcat<version>/*.log
{
daily
rotate 12
compress
copytruncate
missingok
sharedscripts
postrotate
if invoke-rc.d tomcat<version> status > /dev/null 2>&1; then \
invoke-rc.d tomcat<version> restart > /dev/null 2>&1; \
fi;
endscript
}
server.xml config: I also removed _log. from the prefix so it becomes localhost_access.log
vi /var/lib/tomcat<version>/conf/server.xml
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access" suffix=".log" rotatable="false"
pattern="%h %l %u %t "%r" %s %b" />
logging.properties config:
vi /var/lib/tomcat<version>/conf/logging.properties
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
1catalina.org.apache.juli.FileHandler.suffix = log
1catalina.org.apache.juli.FileHandler.rotatable = false
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
2localhost.org.apache.juli.FileHandler.suffix = log
2localhost.org.apache.juli.FileHandler.rotatable = false
3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.prefix = manager.
3manager.org.apache.juli.FileHandler.suffix = log
3manager.org.apache.juli.FileHandler.rotatable = false
4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.
4host-manager.org.apache.juli.FileHandler.suffix = log
4host-manager.org.apache.juli.FileHandler.rotatable = false
The answers quoting "renameOnRotate" are wrong. This only applies to the access log, not to the "main" logging (which is what the question wants since he's quoted 'localhost' log.
If you need both log rotation and not to have the timestamps (which is generally the case), the bad news is that it is not possible out of the box with tomcat :(
The best solution in that case is to configure it to use log4j globally, which is more flexible and will allow you to be setup in that way.
精彩评论