On this page本页内容
logRotate
The logRotate
command is an administrative command that allows you to rotate the MongoDB server log and/or audit log to prevent a single logfile from consuming too much disk space.logRotate
命令是一个管理命令,允许您旋转MongoDB服务器日志和/或审计日志,以防止单个日志文件占用过多的磁盘空间。
You must issue the 必须对logRotate
command against the admin database in the form:admin
数据库发出logRotate
命令,格式如下:
db.adminCommand({logRotate: <target>})
The logRotate
command takes the following parameters:logRotate
命令采用以下参数:
<target> | string |
|
comment | any | optional |
You may also rotate the logs by sending a 您还可以通过向SIGUSR1
signal to the mongod
process.mongod
进程发送SIGUSR1
信号来旋转日志。
For example, if a running 例如,如果正在运行的mongod
instance has a process ID (PID) of 2200
, the following command rotates the log file for that instance on Linux:mongod
实例的进程ID(PID)为2200
,则以下命令在Linux上旋转该实例的日志文件:
kill -SIGUSR1 2200
mongod
instance needs to be running with the --logpath [file]
option in order to use logRotate
logRotate
,mongod
实例需要使用--logpath [file]
选项运行The systemLog.logRotate
setting or --logRotate
option specify logRotate
's behavior.systemLog.logRotate
设置或--logRotate
选项指定logRotate
的行为。
When 当systemLog.logRotate
or --logRotate
are set to rename
, logRotate
renames the existing log file by appending the current timestamp to the filename. systemLog.logRotate
或--logRotate
设置为rename
时,logRotate
通过将当前时间戳附加到文件名来重命名现有日志文件。The appended timestamp has the following form:附加的时间戳具有以下格式:
<YYYY>-<mm>-<DD>T<HH>-<MM>-<SS>
Then 然后logRotate
creates a new log file with the same name as originally specified by the systemLog.path
setting to mongod
or mongos
.logRotate
创建一个新的日志文件,其名称与systemLog.path
设置为mongod
或mongos
最初指定的名称相同。
When 当systemLog.logRotate
or --logRotate
are set to reopen
, logRotate
follows the typical Linux/Unix behavior, and simply closes the log file then reopens a log file with the same name. systemLog.logRotate
或--logRotate
设置为reopen
打开时,logRotate
遵循典型的Linux/Unix行为,只需关闭日志文件,然后重新打开同名的日志文件。With 对于reopen
, mongod
expects that another process renames the file prior to the rotation, and that the reopen results in the creation of a new file.reopen
,mongod
期望在旋转之前另一个进程重命名文件,并且重新打开会导致创建新文件。
The following example rotates both the server log and the audit log:以下示例同时旋转服务器日志和审核日志:
db.adminCommand({logRotate: 1})
The following example rotates only the audit log, and provides a custom message to the log file at time of rotation:以下示例仅旋转审核日志,并在旋转时向日志文件提供自定义消息:
db.adminCommand({logRotate: audit, comment: "Rotating audit log"})