messages.log 的格式当前不可自定义。
如果有更多可解析的日志会有所帮助,您可以使用 Liberty 18.0.0.1 中引入的 JSON 格式。您可以使用messageFormat
server.xml 中的属性进行设置。使用该格式,也许与类似的工具结合使用jq
,可以让您选择/选择要查看的字段。
Liberty 有两种消息格式:
basic
格式,包括时间戳、线程 id、日志级别、记录器名、类名、方法名和消息。
json
格式,其中包括很多字段——例如(这都在一行上):
{
"type":"liberty_message",
"host":"f7cd7d87697a",
"ibm_userDir":"\/opt\/ibm\/wlp\/usr\/",
"ibm_serverName":"defaultServer",
"ibm_datetime":"2018-07-04T20:33:41.873+0000",
"ibm_messageId":"CWWKF0011I",
"ibm_threadId":"0000002b",
"module":"com.ibm.ws.kernel.feature.internal.FeatureManager",
"loglevel":"AUDIT",
"ibm_sequence":"1530736421873_0000000000008",
"message":"CWWKF0011I: The server defaultServer is ready to run a smarter planet."
}
作为如何使用 jq 来实现您所要求的示例,您可以使用 json 格式的 messages.log 运行 Liberty:
然后,您可以使用 jq 查看您的 messages.log,如下所示:
cat messages.log | jq '"[" + .ibm_datetime[5:7] + "/" + .ibm_datetime[8:10] + "/" + .ibm_datetime[0:4] + " " + .ibm_datetime[11:19] + "] " + .loglevel[0:1] + " " + .message' -r
输出示例如下:
[07/19/2018 12:20:23] A CWWKE0001I: The server defaultServer has been launched.
[07/19/2018 12:20:23] A CWWKE0100I: This product is licensed for development, and limited production use. The full license terms can be viewed here: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/18.0.0.1/lafiles/en.html
[07/19/2018 12:20:25] A CWWKG0093A: Processing configuration drop-ins resource: /opt/ibm/wlp/usr/servers/defaultServer/configDropins/defaults/keystore.xml
[07/19/2018 12:20:26] W CWWKF0009W: The server has not been configured to install any features.
[07/19/2018 12:20:26] A CWWKF0011I: The server defaultServer is ready to run a smarter planet.
[07/19/2018 12:20:33] A CWWKE0085I: The server defaultServer is stopping because the JVM is exiting.
[07/19/2018 12:20:33] A CWWKE0036I: The server defaultServer stopped after 10.546 seconds.
虽然这是一个要记住的长字符串,但为了方便起见,您可以给它起别名。
alias prettyLog="jq '\"[\" + .ibm_datetime[5:7] + \"/\" + .ibm_datetime[8:10] + \"/\" + .ibm_datetime[0:4] + \" \" + .ibm_datetime[11:19] + \"] \" + .loglevel[0:1] + \" \" + .message' -r"
cat messages.log | prettyLog
[07/19/2018 12:20:23] A CWWKE0001I: The server defaultServer has been launched.
...