-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0.2, 2.1.0
-
Component/s: Logging
-
Environment:linux (ubuntu/centos)
-
Server 2.7.2
logrotate is a system handler that deals with log files. It is a commonly-used solution across most popular linux distributions.
MongoDB server files are always open by the server, from documentations it shows that one should call the "logRotate" method, either from a signal or through the mongo shell.
Since the logRotate command names the files in a non-logrotate valid format, handling these is not a good solution for automatic "rolling" logs, that auto-expire based on directives.
I believe the code that handles the naming is here: https://github.com/mongodb/mongo/blob/master/src/mongo/util/log.cpp#L108-127
Here's a user's solution on handling the logrotation, and it seems a little like overkill: http://syslog.warten.de/2011/08/logrotate-with-mongodb/
From the man page:
- dateext
Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number. The extension may be configured using the dateformat option.- dateformat format_string
Specify the extension for dateext using the notation similar to strftime(3) function. Only %Y %m %d and %s specifiers are allowed. The default value is -%Y%m%d. Note that also the character separating log name from the extension is part of the dateformat string. The system clock must be set past Sep 9th 2001 for %s to work correctly. Note that the datestamps generated by this format must be lexically sortable (i.e., first the year, then the month then the day. e.g., 2001/12/01 is ok, but 01/12/2001 is not, since 01/11/2002 would sort lower while it is later). This is because when using the rotate option, logrotate sorts all rotated filenames to find out which logfiles are older and should be removed.
Logroate (without copytruncate directive) moves the current (open) file to filename.1 (and any older ones to .2 ,.3 etc).
Then, in the postrotate directive, it issues a command to the mongod process to start writing to a new file.
So it seems like we should be allowing logrotate to handle the naming, expiration, either by default, or by a variable in the logRotate method, or possible a differenc command like "startNewLogFile" or something.
- is depended on by
-
SERVER-7312 Automatic rolling of log files
- Closed
- is duplicated by
-
SERVER-13493 support interoperability with Linux logrotate
- Closed
- is related to
-
SERVER-9358 Log rotation can overwrite previous log files
- Closed
-
SERVER-14053 implementation of server logRotate command breaks O_APPEND semantics which breaks the logrotate utility's copytruncate
- Closed
-
SERVER-4739 Race condition in log rotation (was: SIGUSR1 should set a flag rather than doing rotation)
- Closed
-
SERVER-4797 automatically rotate mongo logs on a schedule or size threshold
- Closed
-
SERVER-1865 Official Linux packages don't set up logrotate
- Closed
- related to
-
SERVER-11087 mongod/mongos fatally asserts when rotating logs and log isn't in original location
- Backlog