Skip to content

Commit 8e5efb8

Browse files
committed
DOCS-14321 logRotate rotates server and audit logs
1 parent ef25da0 commit 8e5efb8

File tree

8 files changed

+103
-60
lines changed

8 files changed

+103
-60
lines changed

source/includes/steps-log-rotate-rename.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ pre: |
3030
action:
3131
language: sh
3232
code: |
33-
db.adminCommand( { logRotate : 1 } )
33+
db.adminCommand( { logRotate : server } )
34+
post: |
35+
If :doc:`auditing </core/auditing>` is enabled, you can specify ``1``
36+
to ``logRotate`` (instead of ``server``) to rotate both the server
37+
and audit logs at the same time, if desired. The audit log will be
38+
rotated in the same fashion as the server log, according to the
39+
:option:`--logRotate <mongod --logRotate>` setting.
3440
---
3541
stepnum: 4
3642
ref: list-new-logfiles

source/reference/command/logRotate.txt

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,44 @@ Definition
1616
.. dbcommand:: logRotate
1717

1818
The :dbcommand:`logRotate` command is an administrative command that
19-
allows you to rotate the MongoDB logs to prevent a single logfile
20-
from consuming too much disk space.
21-
22-
If :doc:`auditing </core/auditing>` is enabled, the
23-
:dbcommand:`logRotate` command also rotates the audit log.
19+
allows you to rotate the MongoDB server log and/or audit log to
20+
prevent a single logfile from consuming too much disk space.
2421

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

2825
.. code-block:: javascript
2926

30-
{ logRotate: 1 }
31-
32-
:dbcommand:`logRotate` takes an optional ``comment`` parameter which
33-
may be of any data type.
34-
35-
.. note::
36-
37-
Your :binary:`~bin.mongod` instance needs to be running with the
38-
:option:`--logpath [file] <mongod --logpath>` option.
27+
db.adminCommand({logRotate: <target>})
28+
29+
The :dbcommand:`logRotate` command takes the following parameters:
30+
31+
.. list-table::
32+
:header-rows: 1
33+
:widths: 20 20 80
34+
35+
* - Parameter
36+
37+
- Type
38+
39+
- Description
40+
41+
* - ``<target>``
42+
43+
- string
44+
45+
- The log or logs to rotate, according to the following:
46+
47+
- ``1`` -- Rotates both the server and audit logs
48+
- ``server`` -- Rotates only the server log
49+
- ``audit`` -- Rotates only the audit log
50+
51+
* - ``comment``
52+
53+
- any
54+
55+
- *optional* A message logged by the server to the log file and
56+
audit file at time of log rotation.
3957

4058
You may also rotate the logs by sending a ``SIGUSR1`` signal to the
4159
:binary:`~bin.mongod` process.
@@ -48,16 +66,27 @@ Definition
4866

4967
kill -SIGUSR1 2200
5068

69+
Limitations
70+
-----------
71+
72+
- Your :binary:`~bin.mongod` instance needs to be running with the
73+
:option:`--logpath [file] <mongod --logpath>` option in order to use
74+
:dbcommand:`logRotate`
75+
76+
- :doc:`Auditing </core/auditing>` must be enabled in order to rotate
77+
the audit log.
78+
5179
Behavior
5280
--------
5381

54-
The :setting:`systemLog.logRotate` setting or :option:`--logRotate <mongod --logRotate>` option
55-
specify :dbcommand:`logRotate`'s behavior.
82+
The :setting:`systemLog.logRotate` setting or
83+
:option:`--logRotate <mongod --logRotate>` option specify
84+
:dbcommand:`logRotate`'s behavior.
5685

57-
When :setting:`systemLog.logRotate` or :option:`--logRotate <mongod --logRotate>` are set to
58-
``rename``, :dbcommand:`logRotate` renames the existing log file by
59-
appending the current timestamp to the filename. The appended timestamp
60-
has the following form:
86+
When :setting:`systemLog.logRotate` or :option:`--logRotate
87+
<mongod --logRotate>` are set to ``rename``, :dbcommand:`logRotate`
88+
renames the existing log file by appending the current timestamp to the
89+
filename. The appended timestamp has the following form:
6190

6291
.. code-block:: none
6392

@@ -67,11 +96,26 @@ Then :dbcommand:`logRotate` creates a new log file with the same
6796
name as originally specified by the :setting:`systemLog.path` setting to
6897
:binary:`~bin.mongod` or :binary:`~bin.mongos`.
6998

70-
When :setting:`systemLog.logRotate` or :option:`--logRotate <mongod --logRotate>` are set to
71-
``reopen``, :dbcommand:`logRotate` follows the typical Linux/Unix
72-
behavior, and simply closes the log file, and then reopens a log file
73-
with the same name. With ``reopen``, :binary:`~bin.mongod` expects that
74-
another process renames the file prior to the rotation, and that the
75-
reopen results in the creation of a new file.
99+
When :setting:`systemLog.logRotate` or :option:`--logRotate
100+
<mongod --logRotate>` are set to ``reopen``, :dbcommand:`logRotate`
101+
follows the typical Linux/Unix behavior, and simply closes the log file
102+
then reopens a log file with the same name. With ``reopen``,
103+
:binary:`~bin.mongod` expects that another process renames the file
104+
prior to the rotation, and that the reopen results in the creation of a
105+
new file.
106+
107+
Examples
108+
--------
109+
110+
The following example rotates both the server log and the audit log:
111+
112+
.. code-block:: javascript
113+
114+
db.adminCommand({logRotate: 1})
115+
116+
The following example rotates only the audit log, and provides a custom
117+
message to the log file at time of rotation:
118+
119+
.. code-block:: javascript
76120

77-
.. :error:`16175` is thrown if logRotate fails
121+
db.adminCommand({logRotate: audit, comment: "Rotating audit log"})

source/reference/configuration-options.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ Core Options
276276

277277
*Default*: rename
278278

279-
The behavior for the :dbcommand:`logRotate` command.
280-
Specify either ``rename`` or ``reopen``:
279+
Determines the behavior for the :dbcommand:`logRotate` command when
280+
rotating the server log and/or the audit log. Specify either
281+
``rename`` or ``reopen``:
281282

282283
- ``rename`` renames the log file.
283284

@@ -287,12 +288,6 @@ Core Options
287288

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

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

297292
.. setting:: systemLog.destination
298293

source/reference/program/mongod.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,9 @@ Core Options
431431

432432
*Default*: rename
433433

434-
Determines the behavior for the :dbcommand:`logRotate` command.
435-
Specify either ``rename`` or ``reopen``:
434+
Determines the behavior for the :dbcommand:`logRotate` command when
435+
rotating the server log and/or the audit log. Specify either
436+
``rename`` or ``reopen``:
436437

437438
- ``rename`` renames the log file.
438439

@@ -442,11 +443,6 @@ Core Options
442443

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

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

451447
.. option:: --timeStampFormat <string>
452448

source/reference/program/mongos.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ Core Options
330330

331331
*Default*: rename
332332

333-
Determines the behavior for the :dbcommand:`logRotate` command.
334-
Specify either ``rename`` or ``reopen``:
333+
Determines the behavior for the :dbcommand:`logRotate` command when
334+
rotating the server log and/or the audit log. Specify either
335+
``rename`` or ``reopen``:
335336

336337
- ``rename`` renames the log file.
337338

@@ -341,10 +342,6 @@ Core Options
341342

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

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

349346
.. option:: --redactClientLogData
350347

source/release-notes/5.0.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ Log Changes to Database Profiler Settings
405405

406406
.. include:: /includes/log-changes-to-database-profiler.rst
407407

408+
Independent Log Rotation for Server and Audit Logs
409+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
410+
411+
Starting in MongoDB 5.0, when :doc:`auditing </core/auditing>` is
412+
enabled, you may now rotate the server and audit logs
413+
independently using the :dbcommand:`logRotate` command.
414+
Previously, :dbcommand:`logRotate` would rotate the two logs together.
415+
408416
``remote`` Field in Slow Operation Logs
409417
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
410418

source/tutorial/configure-auditing.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ 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 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.
154+
The audit file may be rotated with the :dbcommand:`logRotate` command,
155+
either alongside the server log or independently. Rotation specifics
156+
may be configured with the :setting:`systemLog.logRotate` configuration
157+
file option or the :option:`--logRotate <mongod --logRotate>`
158+
command-line option.
158159

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

source/tutorial/rotate-log-files.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ report a live account of all activity and operations to a log file.
1919
When reporting activity data to a log file, by default, MongoDB only
2020
rotates logs in response to the :dbcommand:`logRotate` command, or when
2121
the :binary:`~bin.mongod` or :binary:`~bin.mongos` process receives a
22-
``SIGUSR1`` signal from the operating system.
22+
``SIGUSR1`` signal from the operating system. Both server logs and
23+
:doc:`audit logs </core/auditing>` may be rotated with the
24+
:dbcommand:`logRotate` command, either together or independently.
2325

2426
MongoDB's standard log rotation approach archives the current
2527
log file and starts a new one. To do this, the :binary:`~bin.mongod` or
@@ -88,9 +90,3 @@ file for that instance on Linux:
8890
.. code-block:: bash
8991

9092
kill -SIGUSR1 2200
91-
92-
Interaction with Audit Logs
93-
---------------------------
94-
95-
If :doc:`auditing </core/auditing>` is enabled, the
96-
:dbcommand:`logRotate` command also rotates the audit log.

0 commit comments

Comments
 (0)