We have a liberty-based app on IBM Cloud and we'd like to send structured logs to the LogDNA service.
Currently, when we set com.ibm.ws.logging.message.format=json
it emits the logs in a format like this:
{
"type": "",
"host": "",
"ibm_userDir": "",
"ibm_serverName": "",
"message": "",
"ibm_threadId": "",
"ibm_datetime": "",
"module": "",
"loglevel": "",
"ibm_sequence": "",
"ext_thread": ""
}
Instead, LogDNA works best with a format like this:
{
"line": "This is an awesome log statement",
"app": "myapp",
"level": "INFO",
"env": "production",
"meta": {
"customfield": {
"nestedfield": "nestedvalue"
}
}
}
Is there a way to rename the JSON attributes emitted by liberty?
There isn't a built in way to re-map the field names currently -- but we recognize the value of that. There's an open issue at https://github.com/OpenLiberty/open-liberty/issues/6079 . Please add your comments to make sure it covers what you want.
UPDATE: As of 19.0.0.10, this feature is now supported!
I can finally get the behavior I expected by setting the logging config in my server.xml to something like this:
<logging traceSpecification="${env.TRACE_SPEC}" traceFileName="stdout" isoDateFormat="true"/>
And setting the following environment variables in my kubernetes deployment:
containers:
- env:
- name: TRACE_SPEC
value: "*=info"
- name: WLP_LOGGING_MESSAGE_FORMAT
value: json
- name: WLP_LOGGING_MESSAGE_SOURCE
value: ""
- name: WLP_LOGGING_CONSOLE_FORMAT
value: json
- name: WLP_LOGGING_CONSOLE_LOGLEVEL
value: info
- name: WLP_LOGGING_CONSOLE_SOURCE
value: message,trace,accessLog,ffdc,audit
- name: WLP_LOGGING_JSON_FIELD_MAPPINGS
value: loglevel:level,ibm_datetime:timestamp