来自mongod 4.4命令的不可读终端日志

Unreadable terminal log from mongod 4.4 command

我正在使用 tmux 作为我的默认终端。

以下是终端日志,输入命令sudo mongod

{"t":{"$date":"2021-01-28T18:10:29.521+05:30"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-01-28T18:10:29.523+05:30"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-01-28T18:10:29.523+05:30"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2021-01-28T18:10:29.524+05:30"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":27636,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"khaldrogo-HP-Notebook"}}
{"t":{"$date":"2021-01-28T18:10:29.524+05:30"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.3","gitVersion":"913d6b62acfbb344dde1b116f4161360acd8fd13","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-01-28T18:10:29.524+05:30"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2021-01-28T18:10:29.524+05:30"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2021-01-28T18:10:29.547+05:30"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/data/db","storageEngine":"wiredTiger"}}
{"t":{"$date":"2021-01-28T18:10:29.547+05:30"},"s":"I",  "c":"STORAGE",  "id":22297,   "ctx":"initandlisten","msg":"Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem","tags":["startupWarnings"]}
{"t":{"$date":"2021-01-28T18:10:29.547+05:30"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=1413M,session_max=33000,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,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
...continued

如何获得正确的输出格式?

这个日志输出叫做“结构化日志输出”,是the only log format of MongoDB as of 4.4。以前的版本使用人类可读的日志格式。

有正在开发的工具可以使此日志输出易于阅读:

Mongo 推荐 jq 工具。

此过滤器将生成类似于旧样式​​的输出:

jq -c '.t["$date"] + " " + .s + " " + .c + " [" + .ctx + "] " + .msg' /var/log/mongo/mongo.log

仅过滤警告和(致命)错误可能很有用:

select( .s == "W" or .s =="E" or .s =="F" ) | .t["$date"] + " " + .s + " " + .c + " [" + .ctx + "] " + .msg

"2021-01-28T18:10:29.523+05:30 W ASIO [main] No TransportLayer configured during NetworkInterface startup"

或者试试这个:

select( .s | contains("W","E","F") ) | .t["$date"] + " -> " + .c + " " + .msg + "\n   attr: " + (.attr | tostring) + "\n   tags: " + (.tags|tostring)

jq play