Skip to content

DOCSP-7100,DOCSP-15012 logRotate also rotates audit log #5046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions source/reference/command/logRotate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ Definition
.. dbcommand:: logRotate

The :dbcommand:`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.
allows you to rotate the MongoDB logs to prevent a single logfile
from consuming too much disk space.

You must issue the
:dbcommand:`logRotate`
command against the :term:`admin database` in the form:
If :doc:`auditing </core/auditing>` is enabled, the
:dbcommand:`logRotate` command also rotates the audit log.

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

.. code-block:: javascript

{ logRotate: 1 }
{ logRotate: 1 }

.. note::

Expand All @@ -35,12 +36,14 @@ Definition

You may also rotate the logs by sending a ``SIGUSR1`` signal to the
:binary:`~bin.mongod` process.
If your :binary:`~bin.mongod` has a process ID of 2200, here's how to
send the signal on Linux:

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

.. code-block:: sh

kill -SIGUSR1 2200
kill -SIGUSR1 2200

Behavior
--------
Expand Down
6 changes: 6 additions & 0 deletions source/reference/configuration-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ Core Options

If you specify ``reopen``, you must also set :setting:`systemLog.logAppend` to ``true``.

If :doc:`auditing </core/auditing>` is enabled, the
:dbcommand:`logRotate` command also rotates the audit log according
to the above parameters. For example, if
:setting:`systemLog.logRotate` is set to ``rename``, the audit log
will also be renamed.


.. setting:: systemLog.destination

Expand Down
5 changes: 5 additions & 0 deletions source/reference/program/mongod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ Core Options

If you specify ``reopen``, you must also use :option:`--logappend`.

If :doc:`auditing </core/auditing>` is enabled, the
:dbcommand:`logRotate` command also rotates the audit log according
to the above parameters. For example, if :option:`--logRotate` is set
to ``rename``, the audit log will also be renamed.


.. option:: --timeStampFormat <string>

Expand Down
20 changes: 20 additions & 0 deletions source/reference/program/mongos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ Core Options
existing log and create a new file.


.. option:: --logRotate <string>

*Default*: rename

Determines the behavior for the :dbcommand:`logRotate` command.
Specify either ``rename`` or ``reopen``:

- ``rename`` renames the log file.

- ``reopen`` closes and reopens the log file following the typical
Linux/Unix log rotate behavior. Use ``reopen`` when using the
Linux/Unix logrotate utility to avoid log loss.

If you specify ``reopen``, you must also use :option:`--logappend`.

If :doc:`auditing </core/auditing>` is enabled, the
:dbcommand:`logRotate` command also rotates the audit log according
to the above parameters. For example, if :option:`--logRotate` is set
to ``rename``, the audit log will also be renamed.

.. option:: --redactClientLogData

.. versionadded:: 3.4 Available in MongoDB Enterprise only.
Expand Down
10 changes: 8 additions & 2 deletions source/tutorial/configure-auditing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ a file with the relative path name of ``data/db/auditLog.json``:
in :doc:`/administration/security-checklist` to prevent unauthorized
access.

The audit file rotates at the same time as the server log file.
The audit file is :dbcommand:`rotated <logRotate>` at the same time as
the server log file. Rotation specifics may be configured with the
:setting:`systemLog.logRotate` configuration file option or the
:option:`--logRotate <mongod --logRotate>` command-line option.

You may also specify these options in the :doc:`configuration file
</reference/configuration-options>`:
Expand Down Expand Up @@ -209,7 +212,10 @@ a BSON file with the relative path name of ``data/db/auditLog.bson``:
in :doc:`/administration/security-checklist` to prevent unauthorized
access.

The audit file rotates at the same time as the server log file.
The audit file is :dbcommand:`rotated <logRotate>` at the same time as
the server log file. Rotation specifics may be configured with the
:setting:`systemLog.logRotate` configuration file option or the
:option:`--logRotate <mongod --logRotate>` command-line option.

You may also specify these options in the :doc:`configuration file
</reference/configuration-options>`:
Expand Down
49 changes: 29 additions & 20 deletions source/tutorial/rotate-log-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ Rotate Log Files
Overview
--------

When used with the ``--logpath`` option or :setting:`systemLog.path` setting,
:binary:`~bin.mongod` and :binary:`~bin.mongos` instances 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 :dbcommand:`logRotate` command, or when the
:binary:`~bin.mongod` or :binary:`~bin.mongos` process receives a ``SIGUSR1``
signal from the operating system.
When used with the ``--logpath`` option or :setting:`systemLog.path`
setting, :binary:`~bin.mongod` and :binary:`~bin.mongos` instances
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 :dbcommand:`logRotate` command, or when
the :binary:`~bin.mongod` or :binary:`~bin.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 :binary:`~bin.mongod` or
:binary:`~bin.mongos` instance renames the current log file by appending a
UTC timestamp to the filename, in :term:`ISODate` format. It then
:binary:`~bin.mongos` instance renames the current log file by appending
a UTC timestamp to the filename, in :term:`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
logrotate utility
by setting :setting:`systemLog.logRotate` or
You can also configure MongoDB to support the Linux/Unix ``logrotate``
utility by setting :setting:`systemLog.logRotate` or
``--logRotate`` to ``reopen``. With ``reopen``, :binary:`~bin.mongod`
or :binary:`~bin.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.

Finally, you can configure :binary:`~bin.mongod` to send log data to the
``syslog``. using the :option:`--syslog <mongod --syslog>` option. In this case, you can
take advantage of alternate logrotation tools.
``syslog`` using the :option:`--syslog <mongod --syslog>` option. In
this case, you can take advantage of alternate log rotation tools.

.. seealso:: For information on logging, see the
:ref:`monitoring-standard-loggging` section.
Expand All @@ -50,8 +49,8 @@ By default, MongoDB uses the
``--logRotate rename`` behavior.
With ``rename``, :binary:`~bin.mongod` or
:binary:`~bin.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.
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.

.. include:: /includes/steps/log-rotate-rename.rst

Expand All @@ -68,17 +67,27 @@ the log file following the typical Linux/Unix log rotate behavior.
Syslog Log Rotation
-------------------

With syslog log rotation, :binary:`~bin.mongod` sends log data to the syslog
rather than writing it to a file.
With syslog log rotation, :binary:`~bin.mongod` sends log data to the
syslog rather than writing it to a file.

.. include:: /includes/steps/log-rotate-syslog.rst

Forcing a Log Rotation with ``SIGUSR1``
---------------------------------------

For Linux and Unix-based systems, you can use the ``SIGUSR1`` signal
to rotate the logs for a single process, as in the following:
to rotate the logs for a single process.

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

.. code-block:: sh

kill -SIGUSR1 <mongod process id>
kill -SIGUSR1 2200

Interaction with Audit Logs
---------------------------

If :doc:`auditing </core/auditing>` is enabled, the
:dbcommand:`logRotate` command also rotates the audit log.