Skip to content

Commit 2140975

Browse files
committed
DOCSP-7100,DOCSP-15012 logRotate also rotates audit log
1 parent 9820a9e commit 2140975

File tree

6 files changed

+81
-32
lines changed

6 files changed

+81
-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
@@ -242,6 +242,12 @@ Core Options
242242

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

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

246252
.. setting:: systemLog.destination
247253

source/reference/program/mongod.txt

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

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

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

368373
.. option:: --timeStampFormat <string>
369374

source/reference/program/mongos.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,26 @@ Core Options
250250
existing log and create a new file.
251251

252252

253+
.. option:: --logRotate <string>
254+
255+
*Default*: rename
256+
257+
Determines the behavior for the :dbcommand:`logRotate` command.
258+
Specify either ``rename`` or ``reopen``:
259+
260+
- ``rename`` renames the log file.
261+
262+
- ``reopen`` closes and reopens the log file following the typical
263+
Linux/Unix log rotate behavior. Use ``reopen`` when using the
264+
Linux/Unix logrotate utility to avoid log loss.
265+
266+
If you specify ``reopen``, you must also use :option:`--logappend`.
267+
268+
If :doc:`auditing </core/auditing>` is enabled, the
269+
:dbcommand:`logRotate` command also rotates the audit log according
270+
to the above parameters. For example, if :option:`--logRotate` is set
271+
to ``rename``, the audit log will also be renamed.
272+
253273
.. option:: --redactClientLogData
254274

255275
.. 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
@@ -153,7 +153,10 @@ a file with the relative path name of ``data/db/auditLog.json``:
153153
in :doc:`/administration/security-checklist` to prevent unauthorized
154154
access.
155155

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

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

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

214220
You may also specify these options in the :doc:`configuration file
215221
</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

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

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

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

7675
Forcing a Log Rotation with ``SIGUSR1``
7776
---------------------------------------
7877

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

8285
.. code-block:: sh
8386

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

0 commit comments

Comments
 (0)