Docs Menu

logRotate

On this page

  • Definition
  • Behavior
logRotate

The logRotate command is an administrative command that allows you to rotate the MongoDB logs to prevent a single logfile from consuming too much disk space.

If auditing is enabled, the logRotate command also rotates the audit log.

You must issue the logRotate command against the admin database in the form:

{ logRotate: 1 }

logRotate takes an optional comment parameter which may be of any data type.

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 the mongod process.

For example, if a running mongod instance has a process ID (PID) of 2200, the following command rotates the log file for that instance on Linux:

kill -SIGUSR1 2200

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:

<YYYY>-<mm>-<DD>T<HH>-<MM>-<SS>

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, and 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.

On this page

Give Feedback
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.