- Reference >
- Database Commands >
- Administration Commands >
- logRotate
logRotate¶
On this page
Definition¶
-
logRotate¶ The
logRotatecommand is an administrative command that allows you to rotate the MongoDB server log and/or audit log to prevent a single logfile from consuming too much disk space.You must issue the
logRotatecommand against the admin database in the form:The
logRotatecommand takes the following parameters:Parameter Type Description <target>string The log or logs to rotate, according to the following:
1– Rotates both the server and audit logsserver– Rotates only the server logaudit– Rotates only the audit log
commentany optional A message logged by the server to the log file and audit file at time of log rotation. You may also rotate the logs by sending a
SIGUSR1signal to themongodprocess.For example, if a running
mongodinstance has a process ID (PID) of2200, the following command rotates the log file for that instance on Linux:
Limitations¶
- Your
mongodinstance needs to be running with the--logpath [file]option in order to uselogRotate - Auditing must be enabled in order to rotate the audit log.
Behavior¶
The systemLog.logRotate setting or
--logRotate option specify
logRotate’s behavior.
When systemLog.logRotate or --logRotate are set to rename, logRotate
renames the existing log file by appending the current timestamp to the
filename. The appended timestamp has the following form:
Then logRotate creates a new log file with the same
name as originally specified by the systemLog.path setting to
mongod or mongos.
When systemLog.logRotate or --logRotate are set to reopen, logRotate
follows the typical Linux/Unix behavior, and simply closes the log file
then reopens a log file with the same name. With reopen,
mongod expects that another process renames the file
prior to the rotation, and that the reopen results in the creation of a
new file.
Examples¶
The following example rotates both the server log and the audit log:
The following example rotates only the audit log, and provides a custom message to the log file at time of rotation: