On this page
When used with the
--logpath option or
report a live account of all activity and operations to a log file.
When reporting activity data to a log file, by default, MongoDB only
rotates logs in response to the
logRotate command, or when
mongos process receives a
SIGUSR1 signal from the operating system.
MongoDB's standard log rotation approach archives the current
log file and starts a new one. To do this, the
mongos instance renames the current log file by appending
a UTC 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.
You can also configure MongoDB to support the Linux/Unix
utility by setting
mongos closes the log file, and
then reopens a log file with the same name, expecting that another
process renamed the file prior to rotation.
To rotate the log files, you must perform one of these steps:
Run the MongoDB
Run the Linux/Unix
See the examples later on this page.
For information on logging, see the Process Logging section.
By default, MongoDB uses the
--logRotate rename behavior.
mongos renames the current log file by appending a UTC
timestamp to the filename, opens a new log file, closes the old log
file, and sends all new log entries to the new log file.
List the new log files to view the newly-created log:
Rotating log files does not modify the "old" rotated log files. When
you rotate a log, you rename the
server1.log file to include
the timestamp, and a new, empty
server1.log file receives all
new log input.
Log rotation with
--logRotate reopen closes and opens
the log file following the typical Linux/Unix log rotate behavior.
With syslog log rotation,
mongod sends log data to the
syslog rather than writing it to a file.
Starting in version 4.2, MongoDB includes the component in its log messages to
For Linux and Unix-based systems, you can use the
to rotate the logs for a single 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