On this page
getLog
在本页面
getLog
getLog命令具有以下语法:
{ getLog: <value> }
getLog的可能值为:
global
-返回所有最近的日志条目的组合输出。rs
-如果mongod是replica set的一部分,则getLog返回与副本集活动有关的最新通知。startupWarnings
-从当前进程开始时返回 MongoDB 日志中可能包含错误或警告的日志。如果mongod启动时没有警告,则此过滤器可能返回空数组。
Returns: | 一个文档,其中包含一系列日志事件,它们为log ,而日志事件的数量为totalLinesWritten 。 |
---|
Behavior
指定*
到getLog以返回mongod的可用日志过滤器列表。
getLog会截断任何包含 512 个以上字符的事件。
Examples
检索可用的日志过滤器
以下操作返回可用的日志过滤器,以传递给getLog
db.adminCommand( { getLog: "*" } )
该操作返回以下文档:
{ "names" : [ "global", "rs", "startupWarnings" ], "ok" : 1 }
从日志中检索最近的事件
以下操作检索mongod的最新global
事件
db.adminCommand( { getLog : "global" } )
该操作返回类似于以下内容的文档:
{
"totalLinesWritten" : <int>,
"log" : [
"2017-07-11T12:24:46.094-0400 I CONTROL [initandlisten] MongoDB starting : pid=67001 port=27017 dbpath=./ 64-bit host=<host>",
"2017-07-11T12:24:46.094-0400 I CONTROL [initandlisten] db version v3.4.4",
"2017-07-11T12:24:46.096-0400 I - [initandlisten] Detected data files in ./ created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.",
"2017-07-11T12:24:46.096-0400 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),",
"2017-07-11T12:24:47.099-0400 I NETWORK [thread1] waiting for connections on port 27017",
"2017-07-11T12:57:42.517-0400 I NETWORK [thread1] connection accepted from 127.0.0.1:55291 #1 (1 connection now open)",
"2017-07-11T12:57:42.518-0400 I NETWORK [conn1] received client metadata from 127.0.0.1:55291 conn1: { driver: { name: \"PyMongo\", version: \"3.4.0\" }, os: { type: \"Darwin\", name: \"Darwin\", architecture: \"x86_64\", version: \"10.11.6\" }, platform: \"CPython 3.5.1.final.0\" }",
],
"ok" : 1
}
突出显示的行被截断,因为它超过了 512 个字符。