- Administration >
- Administration Tutorials >
- Configuration, Maintenance, and Analysis >
- Rotate Log Files
Rotate Log Files¶
On this page
Overview¶
Log rotation using MongoDB’s standard approach archives the current
log file and starts a new one. To do this, the mongod
or
mongos
instance renames the current log file by appending a
UTC (GMT) timestamp to the filename, in ISODate format. It then
opens a new log file, closes the old log file, and sends all new log
entries to the new log file.
MongoDB’s standard approach to log rotation only rotates logs
in response to the logRotate
command, or when the
mongod
or mongos
process receives a SIGUSR1
signal from the operating system.
Alternately, you may configure mongod to send log data to syslog
. In
this case, you can take advantage of alternate logrotation tools.
See also
For information on logging, see the Process Logging section.
Log Rotation With MongoDB¶
The following steps create and rotate a log file:
Start a
mongod
with verbose logging, with appending enabled, and with the following log file:In a separate terminal, list the matching files:
For results, you get:
Rotate the log file using one of the following methods.
List the matching files again:
For results you get something similar to the following. The timestamps will be different.
The example results indicate a log rotation performed at exactly
11:30 pm
onNovember 24th, 2011 UTC
, which is the local time offset by the local time zone. The original log file is the one with the timestamp. The new log isserver1.log
file.If you issue a second
logRotate
command an hour later, then an additional file would appear when listing matching files, as in the following example:This operation does not modify the
server1.log.2011-11-24T23-30-00
file created earlier, whileserver1.log.2011-11-25T00-30-00
is the previousserver1.log
file, renamed.server1.log
is a new, empty file that receives all new log output.
Syslog Log Rotation¶
New in version 2.2.
To configure mongod to send log data to syslog rather than writing log data to a file, use the following procedure.