写mongodb日志
The following steps create and rotate a log file:
-
Start a mongod with verbose logging, with appending enabled, and with the following log file:
mongod -v --logpath /var/log/mongodb/server1.log --logappend
-
In a separate terminal, list the matching files:
ls /var/log/mongodb/server1.log*
For results, you get:
server1.log
-
Rotate the log file using one of the following methods.
-
From the mongo shell, issue the logRotate command from the admin database:
use admin db.runCommand( { logRotate : 1 } )
This is the only available method to rotate log files on Windows systems.
-
From the UNIX shell, rotate logs for a single process by issuing the following command:
kill -SIGUSR1 <mongod process id>
-
From the UNIX shell, rotate logs for all mongod processes on a machine by issuing the following command:
killall -SIGUSR1 mongod
-
-
List the matching files again:
ls /var/log/mongodb/server1.log*
For results you get something similar to the following. The timestamps will be different.
server1.log server1.log.2011-11-24T23-30-00
The example results indicate a log rotation performed at exactly 11:30 pm on November 24th, 2011 UTC, which is the local time offset by the local time zone. The original log file is the one with the timestamp. The new log is server1.log file.
If you issue a second logRotate command an hour later, then an additional file would appear when listing matching files, as in the following example:
server1.log server1.log.2011-11-24T23-30-00 server1.log.2011-11-25T00-30-00
This operation does not modify the server1.log.2011-11-24T23-30-00 file created earlier, while server1.log.2011-11-25T00-30-00 is the previous server1.log file, renamed. server1.log is a new, empty file that receives all new log output.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 【.NET】调用本地 Deepseek 模型