WebSphere Liberty在message.log中自定义时间戳

WebSphere Liberty在message.log中自定义时间戳,websphere,websphere-liberty,open-liberty,Websphere,Websphere Liberty,Open Liberty,我不喜欢Liberty服务器显示元数据的方式。您可以选择在console.log中根本没有元数据,也可以选择在message.log中有效地使用元数据 message.log中的当前格式如下所示: [7/13/18 14:00:00:000 CEST] 000006a4 v.k.j.G I Running G [7/13/18 14:00:00:002 CEST] 000006a4 v.k.j.G

我不喜欢Liberty服务器显示元数据的方式。您可以选择在console.log中根本没有元数据,也可以选择在message.log中有效地使用元数据

message.log中的当前格式如下所示:

[7/13/18 14:00:00:000 CEST] 000006a4 v.k.j.G                                I Running G
[7/13/18 14:00:00:002 CEST] 000006a4 v.k.j.G                                          W Nothing to delete.
[7/13/18 14:00:00:002 CEST] 000006a4 vv.k.j.G                                 I Import: update T
[7/13/18 14:00:00:003 CEST] 000006a4 v.k.j.G                                     I next import schedule is Fri Jul 13 15:00:00 CEST 2018
[7/13/18 14:00:00] I Running G 
[7/13/18 14:00:00] W Nothing to delete 
[7/13/18 14:00:00] I Import: update T
这看起来并没有那么糟糕,但是一旦输出更长并且需要换行符,它就是一堵很难阅读的杂乱文本的大墙

我想将时间戳自定义为以下内容:

[7/13/18 14:00:00:000 CEST] 000006a4 v.k.j.G                                I Running G
[7/13/18 14:00:00:002 CEST] 000006a4 v.k.j.G                                          W Nothing to delete.
[7/13/18 14:00:00:002 CEST] 000006a4 vv.k.j.G                                 I Import: update T
[7/13/18 14:00:00:003 CEST] 000006a4 v.k.j.G                                     I next import schedule is Fri Jul 13 15:00:00 CEST 2018
[7/13/18 14:00:00] I Running G 
[7/13/18 14:00:00] W Nothing to delete 
[7/13/18 14:00:00] I Import: update T
我还想交换月份和日期[dd/mm/yy]

我的server.xml是这样的

     <logging
    maxFiles="10"
    traceFormat="ADVANCED"
    isoDateFormat="false"></logging>

如何自定义message.log输出以仅显示简单的(欧洲)日期和时间格式,而不显示类别信息?

messages.log的格式当前不可自定义

如果有更多可解析的日志会有所帮助,那么可以使用Liberty 18.0.0.1中引入的JSON格式。您可以使用server.xml中的
messageFormat
属性进行设置。使用这种格式,或者结合像
jq
这样的工具,可以让您选择要查看的字段

Liberty有两种消息格式:

basic
格式,包括时间戳、线程id、日志级别、日志名、类名、方法名和消息

json
格式,其中包括许多字段——例如(所有字段都在一行上):

作为如何使用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.
输出示例如下所示:

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.
...

谢谢你的回答。什么样的messageFormat参数可用?用2种消息格式的信息更新了上面的答案我接受你的答案,因为这可能是我所能期望的最准确的答案。谢谢分享你的建议informations@MartinWasGehtSieDasAn我更新了我的答案,加入了一种方法,您可以使用jq来重新格式化json日志,从而获得所需的格式