定義
logRotateThe
logRotatecommand 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.You must issue the
logRotatecommand against the admin database.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
構文
このコマンドの構文は、次のとおりです。
db.adminCommand( { logRotate: <integer or string>, comment: <string> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
|---|---|---|
| 整数または文字列 | ローテーションするログは、次のように表示されます。
|
| string | 任意。ログローテーション時にサーバーがログファイルと監査ファイルに記録するメッセージ。 |
SIGUSR1 シグナルを mongod プロセスに送信してログをローテーションすることもできます。
たとえば、実行中の mongod インスタンスのプロセス ID(PID)が 2200 の場合、次のコマンドは Linux 上でそのインスタンスのログファイルをローテーションします。
kill -SIGUSR1 2200
制限
Your
mongodinstance needs to be running with the--logpath [file]option in order to uselogRotate監査ログをローテーションするには、監査を有効にする必要があります。
動作
The systemLog.logRotate setting or --logRotate option specify logRotate's behavior.
When systemLog.logRotate or --logRotate are set to rename, logRotate renames the existing log file by appending the current timestamp to the filename. 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.
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. 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.
例
次の例では、サーバーログと監査ログの両方をローテーションしています。
db.adminCommand( { logRotate: 1 } )
次の例では、監査ログのみをローテーションし、ローテーション時にログファイルにカスタムメッセージを提供します。
db.adminCommand( { logRotate: "audit", comment: "Rotating audit log" } )