Reputation: 305
I dont like the way how the Liberty Server is showing MetaData. You have the choice of no MetaData at all in the console.log or WAY to much to work with it effective in the message.log.
my current formatting in the message.log looks like this:
[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
This does not look that bad, but as soon as the output is longer and needs a linebreak it is just a big wall of cluttering text which is hard to read.
I would like to customize the timestamp to something like this:
[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
I also would like to also swap around the month and the day [dd/mm/yy]
my server.xml is looking like this
<logging
maxFiles="10"
traceFormat="ADVANCED"
isoDateFormat="false"></logging>
I decided to use isoDateFormat="false"
since it just clutters the output with even more characters.
[2018-07-13T13:59:27.337+0200]
How can I customize the message.log output to only show a simple (european) date- and timeformat without the class-information?
Upvotes: 2
Views: 1490
Reputation: 276
The format of the messages.log isn't currently customizable.
If it would help to have more parseable logs, you could use the JSON format introduced in Liberty 18.0.0.1. You can set that using the messageFormat
attribute in the server.xml. Using that format, perhaps in combination with a tool like jq
, can let you pick/choose which fields to see.
Liberty has two message formats:
basic
format, which includes timestamp, thread id, loglevel, loggername, classname, methodname, and the message.
json
format, which includes lots of fields -- for example (this would all be on one line):
{
"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."
}
As an example of how to use jq to achieve what you're asking you could run Liberty with messages.log in json format:
You could then use jq to view your messages.log as follows:
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
A sample of the output is as follows:
[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.
While that's a long string to remember, you could alias it for convenience.
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.
...
Upvotes: 2