@@ -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+
5179Behavior
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
6796name 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"})
0 commit comments