@@ -7,111 +7,74 @@ Rotate Log Files
7
7
Overview
8
8
--------
9
9
10
- Log rotation using MongoDB's standard approach archives the current
10
+ When used with the :option:`--logpath` option or :setting:`systemLog.logPath` setting,
11
+ :program:`mongod` and :program:`mongos` instances report
12
+ a live account of all activity and operations to a log file.
13
+ When reporting activity data to a log file, by default, MongoDB only rotates logs
14
+ in response to the :dbcommand:`logRotate` command, or when the
15
+ :program:`mongod` or :program:`mongos` process receives a ``SIGUSR1``
16
+ signal from the operating system.
17
+
18
+ MongoDB's standard log rotation approach archives the current
11
19
log file and starts a new one. To do this, the :program:`mongod` or
12
20
:program:`mongos` instance renames the current log file by appending a
13
- UTC (GMT) timestamp to the filename, in :term:`ISODate` format. It then
21
+ UTC timestamp to the filename, in :term:`ISODate` format. It then
14
22
opens a new log file, closes the old log file, and sends all new log
15
23
entries to the new log file.
16
24
17
- MongoDB's standard approach to log rotation only rotates logs
18
- in response to the :dbcommand:`logRotate` command, or when the
19
- :program:`mongod` or :program:`mongos` process receives a ``SIGUSR1``
20
- signal from the operating system.
25
+ You can also configure MongoDB to support the Linux/Unix
26
+ logrotate utility
27
+ by setting :setting:`systemLog.logRotate` or
28
+ :option:`--logRotate` to ``reopen``. With ``reopen``, :program:`mongod`
29
+ or :program:`mongos` closes the log file, and
30
+ then reopens a log file with the same name, expecting that another
31
+ process renamed the file prior to rotation.
21
32
22
- Alternately, you may configure mongod to send log data to ``syslog``. In
23
- this case, you can take advantage of alternate logrotation tools.
33
+ Finally, you can configure :program:`mongod` to send log data to the
34
+ ``syslog``. using the :option:`--syslog` option. In this case, you can
35
+ take advantage of alternate logrotation tools.
24
36
25
37
.. seealso:: For information on logging, see the
26
38
:ref:`monitoring-standard-loggging` section.
27
39
28
- Log Rotation With MongoDB
29
- -------------------------
30
-
31
- The following steps create and rotate a log file:
32
-
33
- 1. Start a :program:`mongod` with verbose logging, with appending
34
- enabled, and with the following log file:
35
-
36
- .. code-block:: javascript
37
-
38
- mongod -v --logpath /var/log/mongodb/server1.log --logappend
39
-
40
- #. In a separate terminal, list the matching files:
41
-
42
- .. code-block:: javascript
43
-
44
- ls /var/log/mongodb/server1.log*
45
-
46
- For results, you get:
47
-
48
- .. code-block:: javascript
40
+ Default Log Rotation Behavior
41
+ -----------------------------
49
42
50
- server1.log
43
+ By default, MongoDB uses the
44
+ :option:`--logRotate rename <--logRotate>` behavior.
45
+ With ``rename``, :program:`mongod` or
46
+ :program:`mongos` renames the current log file by appending a UTC
47
+ timestamp to the filename, opens a new log file, closes the old log file,
48
+ and sends all new log entries to the new log file.
51
49
52
- #. Rotate the log file using *one* of the following methods.
50
+ .. include:: /includes/steps/ log-rotate-rename.rst
53
51
54
- - From the :program:`mongo` shell, issue the :dbcommand:`logRotate `
55
- command from the ``admin`` database:
52
+ Log Rotation with ``--logRotate reopen` `
53
+ ----------------------------------------
56
54
57
- .. code-block :: javascript
55
+ .. versionadded :: 3.0.0
58
56
59
- use admin
60
- db.runCommand( { logRotate : 1 } )
57
+ Log rotation with :option:`--logRotate reopen <--logRotate>` closes and opens
58
+ the log file following the typical Linux/Unix log rotate behavior.
61
59
62
- This is the only available method to rotate log files on
63
- Windows systems.
64
-
65
- - For Linux systems, rotate logs for a single process by issuing
66
- the following command:
67
-
68
- .. code-block:: javascript
69
-
70
- kill -SIGUSR1 <mongod process id>
71
-
72
- #. List the matching files again:
73
-
74
- .. code-block:: javascript
75
-
76
- ls /var/log/mongodb/server1.log*
77
-
78
- For results you get something similar to the following. The
79
- timestamps will be different.
80
-
81
- .. code-block:: none
82
-
83
- server1.log server1.log.2011-11-24T23-30-00
84
-
85
- The example results indicate a log rotation performed at exactly
86
- ``11:30 pm`` on ``November 24th, 2011 UTC``, which is the local time
87
- offset by the local time zone. The original log file is the one with
88
- the timestamp. The new log is ``server1.log`` file.
89
-
90
- If you issue a second :dbcommand:`logRotate` command an hour later,
91
- then an additional file would appear when listing matching files,
92
- as in the following example:
93
-
94
- .. code-block:: none
95
-
96
- server1.log server1.log.2011-11-24T23-30-00 server1.log.2011-11-25T00-30-00
97
-
98
- This operation does not modify the
99
- ``server1.log.2011-11-24T23-30-00`` file created earlier, while
100
- ``server1.log.2011-11-25T00-30-00`` is the previous ``server1.log``
101
- file, renamed. ``server1.log`` is a new, empty file that receives
102
- all new log output.
60
+ .. include:: /includes/steps/log-rotate-reopen.rst
103
61
104
62
Syslog Log Rotation
105
63
-------------------
106
64
107
65
.. versionadded:: 2.2
108
66
109
- To configure mongod to send log data to syslog rather than writing log
110
- data to a file, use the following procedure.
67
+ With syslog log rotation, :program:`mongod` sends log data to the syslog
68
+ rather than writing it to a file.
69
+
70
+ .. include:: /includes/steps/log-rotate-syslog.rst
71
+
72
+ Forcing a Log Rotation with ``SIGUSR1``
73
+ ---------------------------------------
111
74
112
- 1. Start a :program:`mongod` with the :setting:`~systemLog.syslogFacility` option.
75
+ For Linux and Unix-based systems, you can use the ``SIGURS1`` signal
76
+ to rotate the logs for a single process, as in the following:
113
77
114
- #. Store and rotate the log output using your system's default log
115
- rotation mechanism.
78
+ .. code-block:: sh
116
79
117
- .. important:: You cannot use :setting:`~systemLog.syslogFacility` with :setting:`systemLog.path`.
80
+ kill -SIGUSR1 <mongod process id>
0 commit comments