Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4905

logRotate should conform to standard log rotation mechanisms

    • 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.

            mark.benvenuto@mongodb.com Mark Benvenuto
            miketheman Michael A. Fiedler
            23 Vote for this issue
            27 Start watching this issue