Skip to content

Commit 40395ba

Browse files
committed
DOCSP-7100,DOCSP-15012 logRotate also rotates audit log
1 parent e1eca14 commit 40395ba

File tree

6 files changed

+82
-32
lines changed

6 files changed

+82
-32
lines changed

source/reference/command/logRotate.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ Definition
1616
.. dbcommand:: logRotate
1717

1818
The :dbcommand:`logRotate` command is an administrative command that
19-
allows you to rotate
20-
the MongoDB logs to prevent a single logfile from consuming too
21-
much disk space.
19+
allows you to rotate the MongoDB logs to prevent a single logfile
20+
from consuming too much disk space.
2221

23-
You must issue the
24-
:dbcommand:`logRotate`
25-
command against the :term:`admin database` in the form:
22+
If :doc:`auditing </core/auditing>` is enabled, the
23+
:dbcommand:`logRotate` command also rotates the audit log.
24+
25+
You must issue the :dbcommand:`logRotate` command against the
26+
:term:`admin database` in the form:
2627

2728
.. code-block:: javascript
2829

29-
{ logRotate: 1 }
30+
{ logRotate: 1 }
3031

3132
.. note::
3233

@@ -35,12 +36,14 @@ Definition
3536

3637
You may also rotate the logs by sending a ``SIGUSR1`` signal to the
3738
:binary:`~bin.mongod` process.
38-
If your :binary:`~bin.mongod` has a process ID of 2200, here's how to
39-
send the signal on Linux:
39+
40+
For example, if a running :binary:`~bin.mongod` instance has a
41+
process ID (PID) of ``2200``, the following command rotates the log
42+
file for that instance on Linux:
4043

4144
.. code-block:: sh
4245

43-
kill -SIGUSR1 2200
46+
kill -SIGUSR1 2200
4447

4548
Behavior
4649
--------

source/reference/configuration-options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ Core Options
285285

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

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

289295
.. setting:: systemLog.destination
290296

source/reference/program/mongod.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ Core Options
431431

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

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

435440
.. option:: --timeStampFormat <string>
436441

source/reference/program/mongos.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,27 @@ Core Options
317317
existing log and create a new file.
318318

319319

320+
.. option:: --logRotate <string>
321+
322+
*Default*: rename
323+
324+
Determines the behavior for the :dbcommand:`logRotate` command.
325+
Specify either ``rename`` or ``reopen``:
326+
327+
- ``rename`` renames the log file.
328+
329+
- ``reopen`` closes and reopens the log file following the typical
330+
Linux/Unix log rotate behavior. Use ``reopen`` when using the
331+
Linux/Unix logrotate utility to avoid log loss.
332+
333+
If you specify ``reopen``, you must also use :option:`--logappend`.
334+
335+
If :doc:`auditing </core/auditing>` is enabled, the
336+
:dbcommand:`logRotate` command also rotates the audit log according
337+
to the above parameters. For example, if :option:`--logRotate` is set
338+
to ``rename``, the audit log will also be renamed.
339+
340+
320341
.. option:: --redactClientLogData
321342

322343
.. versionadded:: 3.4 Available in MongoDB Enterprise only.

source/tutorial/configure-auditing.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ a file with the relative path name of ``data/db/auditLog.json``:
151151
in :doc:`/administration/security-checklist` to prevent unauthorized
152152
access.
153153

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

156159
You may also specify these options in the :doc:`configuration file
157160
</reference/configuration-options>`:
@@ -207,7 +210,10 @@ a BSON file with the relative path name of ``data/db/auditLog.bson``:
207210
in :doc:`/administration/security-checklist` to prevent unauthorized
208211
access.
209212

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

212218
You may also specify these options in the :doc:`configuration file
213219
</reference/configuration-options>`:

source/tutorial/rotate-log-files.txt

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@ Rotate Log Files
1313
Overview
1414
--------
1515

16-
When used with the ``--logpath`` option or :setting:`systemLog.path` setting,
17-
:binary:`~bin.mongod` and :binary:`~bin.mongos` instances report
18-
a live account of all activity and operations to a log file.
19-
When reporting activity data to a log file, by default, MongoDB only rotates logs
20-
in response to the :dbcommand:`logRotate` command, or when the
21-
:binary:`~bin.mongod` or :binary:`~bin.mongos` process receives a ``SIGUSR1``
22-
signal from the operating system.
16+
When used with the ``--logpath`` option or :setting:`systemLog.path`
17+
setting, :binary:`~bin.mongod` and :binary:`~bin.mongos` instances
18+
report a live account of all activity and operations to a log file.
19+
When reporting activity data to a log file, by default, MongoDB only
20+
rotates logs in response to the :dbcommand:`logRotate` command, or when
21+
the :binary:`~bin.mongod` or :binary:`~bin.mongos` process receives a
22+
``SIGUSR1`` signal from the operating system.
2323

2424
MongoDB's standard log rotation approach archives the current
2525
log file and starts a new one. To do this, the :binary:`~bin.mongod` or
26-
:binary:`~bin.mongos` instance renames the current log file by appending a
27-
UTC timestamp to the filename, in :term:`ISODate` format. It then
26+
:binary:`~bin.mongos` instance renames the current log file by appending
27+
a UTC timestamp to the filename, in :term:`ISODate` format. It then
2828
opens a new log file, closes the old log file, and sends all new log
2929
entries to the new log file.
3030

31-
You can also configure MongoDB to support the Linux/Unix
32-
logrotate utility
33-
by setting :setting:`systemLog.logRotate` or
31+
You can also configure MongoDB to support the Linux/Unix ``logrotate``
32+
utility by setting :setting:`systemLog.logRotate` or
3433
``--logRotate`` to ``reopen``. With ``reopen``, :binary:`~bin.mongod`
3534
or :binary:`~bin.mongos` closes the log file, and
3635
then reopens a log file with the same name, expecting that another
3736
process renamed the file prior to rotation.
3837

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

4342
.. seealso:: For information on logging, see the
4443
:ref:`monitoring-standard-loggging` section.
@@ -50,8 +49,8 @@ By default, MongoDB uses the
5049
``--logRotate rename`` behavior.
5150
With ``rename``, :binary:`~bin.mongod` or
5251
:binary:`~bin.mongos` renames the current log file by appending a UTC
53-
timestamp to the filename, opens a new log file, closes the old log file,
54-
and sends all new log entries to the new log file.
52+
timestamp to the filename, opens a new log file, closes the old log
53+
file, and sends all new log entries to the new log file.
5554

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

@@ -66,8 +65,8 @@ the log file following the typical Linux/Unix log rotate behavior.
6665
Syslog Log Rotation
6766
-------------------
6867

69-
With syslog log rotation, :binary:`~bin.mongod` sends log data to the syslog
70-
rather than writing it to a file.
68+
With syslog log rotation, :binary:`~bin.mongod` sends log data to the
69+
syslog rather than writing it to a file.
7170

7271
Starting in version 4.2, MongoDB includes the :ref:`component
7372
<log-message-components>` in its log messages to ``syslog``.
@@ -78,8 +77,18 @@ Forcing a Log Rotation with ``SIGUSR1``
7877
---------------------------------------
7978

8079
For Linux and Unix-based systems, you can use the ``SIGUSR1`` signal
81-
to rotate the logs for a single process, as in the following:
80+
to rotate the logs for a single process.
81+
82+
For example, if a running :binary:`~bin.mongod` instance has a
83+
process ID (PID) of ``2200``, the following command rotates the log
84+
file for that instance on Linux:
8285

8386
.. code-block:: sh
8487

85-
kill -SIGUSR1 <mongod process id>
88+
kill -SIGUSR1 2200
89+
90+
Interaction with Audit Logs
91+
---------------------------
92+
93+
If :doc:`auditing </core/auditing>` is enabled, the
94+
:dbcommand:`logRotate` command also rotates the audit log.

0 commit comments

Comments
 (0)