我不喜欢Liberty Server显示元数据的方式。您可以在console.log中选择完全不使用元数据,也可以选择在message.log中有效使用它的方式。
message.log中我当前的格式如下:
textView.post(new Runnable()
{
public void run()
{
textView.setText(String.valueOf(view.getHeight()));
}
});
看起来还不错,但是只要输出更长并且需要换行,它就只是一堵杂乱的文本,很难阅读。
我想自定义时间戳,如下所示:
[7/13/18 14:00:00:000 CEST] 000006a4 vwg.kdvdb.jobs.GocatImportJob I Running GocatImport
[7/13/18 14:00:00:002 CEST] 000006a4 vwg.kdvdb.gocat.GdgXImport W Nothing to delete.
[7/13/18 14:00:00:002 CEST] 000006a4 vwg.kdvdb.gocat.GocatImportService I Import: update Testertexte
[7/13/18 14:00:00:003 CEST] 000006a4 vwg.kdvdb.jobs.GocatImportJob I next import schedule is Fri Jul 13 15:00:00 CEST 2018
我也想在[dd / mm / yy]的月份和日期前后进行交换
我的server.xml看起来像这样
[7/13/18 14:00:00] I Running GocatImport
[7/13/18 14:00:00] W Nothing to delete
[7/13/18 14:00:00] I Import: update Testertexte
我决定使用 <logging
maxFiles="10"
traceFormat="ADVANCED"
isoDateFormat="false"></logging>
,因为它会使输出中的字符杂乱无章。
isoDateFormat="false"
如何自定义message.log输出,使其仅显示简单的(欧洲)日期和时间格式而没有类信息?
答案 0 :(得分:2)
messages.log的格式当前无法自定义。
如果这有助于拥有更多可解析的日志,则可以使用Liberty 18.0.0.1中引入的JSON格式。您可以使用server.xml中的messageFormat
属性进行设置。使用该格式,也许结合使用jq
之类的工具,可以让您选择/选择要查看的字段。
自由有两种消息格式:
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.
...