logRotate
Definition
logRotate
- The
logRotate
command is an administrative command thatallows you to rotatethe MongoDB logs to prevent a single logfile from consuming toomuch disk space.
You must issue thelogRotate
command against the admin database in the form:
- { logRotate: 1 }
Note
Your mongod
instance needs to be running with the—logpath [file]
option.
You may also rotate the logs by sending a SIGUSR1
signal to themongod
process.If your mongod
has a process ID of 2200, here’s how tosend the signal on Linux:
- kill -SIGUSR1 2200
Behavior
Changed in version 3.0.0.
The systemLog.logRotate
setting or —logRotate
optionspecify logRotate
’s behavior.
When systemLog.logRotate
or —logRotate
are set torename
, logRotate
renames the existing log file byappending the current timestamp to the filename. The appended timestamphas the following form:
- <YYYY>-<mm>-<DD>T<HH>-<MM>-<SS>
Then logRotate
creates a new log file with the samename as originally specified by the systemLog.path
setting tomongod
or mongos
.
When systemLog.logRotate
or —logRotate
are set toreopen
, logRotate
follows the typical Linux/Unixbehavior, and simply closes the log file, and then reopens a log filewith the same name. With reopen
, mongod
expects thatanother process renames the file prior to the rotation, and that thereopen results in the creation of a new file.