IBM Support

Server JSON logging

News


Abstract

Server logs can now be formatted in JSON format.

Content

What is it?

Server logs can now be formatted in JSON format. You can enable JSON formatting in the server by navigating to the Server Logging tab as follows: Server Properties -> Logging, then selecting the Server Logging tab as shown in the following figure:
image 12635
The Server Logging tab is used to configure logging and tracing for the application server.
  • Maximum log file size: The maximum size, in megabytes, that a log file can reach before it is rolled over; a value of 0 means no limit.
  • Maximum log files: Maximum number of log files that are kept before the oldest file is removed; a value of 0 means no limit. If an enforced maximum file size exists, this setting is used to determine how many of each of the log files are kept. This setting also applies to the number of exception logs that summarize exceptions that occurred on a particular day. So if this number is 10, you might have 10 message logs, 10 trace logs, and 10 exception summaries in the "logs/ffdc/" directory.
  • Log directory: Directory for all log files.
  • Use the ISO 8601 date format: The date and time use a locale-specific format or the ISO-8601 format.
  • Message file name: Name of the file to which message output is written relative to the configured log directory. This file always exists and contains INFO and other (AUDIT, WARNING, ERROR, FAILURE) messages, in addition to System.out and System.err. This log also contains time stamps and the issuing thread ID. If the log file is rolled over, the names of earlier log files have the format messages_timestamp.log.
  • Message format: The required format for the messages.log file. Valid values are SIMPLE, TBASIC, or JSON format. The TBASIC format is equivalent to the WebSphere Application Server traditional basic format. Using the TBASIC format option allows users that use log parsers that work with the WebSphere Application Server basic format to use the same parsers with integrated application server logs. 
  • Message source: The list of comma-separated sources that route to the messages.log file. This property applies only when the message format is set to JSON. Valid values are message, trace, accessLog, and ffdc.
  • Trace file name: Name of the file to which trace output is written relative to the configured log directory. The trace.log file is only created if a trace specification is set that includes log levels below INFO.
  • Trace specification: A trace specification that conforms to the trace specification grammar and specifies the initial state for various trace components. The trace specification is used to selectively enable trace. An empty value is allowed and treated as 'disable all trace'. Any component that is not specified is initialized to a default state of *=info.

    The format of the log detail level specification is:
    <component>=<level>
    Where <component> is the component for which to set a log detail level, and <level> is one of the valid logger levels. Separate multiple log detail level specifications with colons (:). The valid logger levels for the application server are as follows:

    off
    Logging is turned off.
    fatal
    Task cannot continue and component, application, and server cannot function.
    severe
    Task cannot continue but component, application, and server can still function. This level can also indicate an impending unrecoverable error.
    warning
    Potential error or impending error. This level can also indicate a progressive failure (for example, the potential leaking of resources).
    audit
    Significant event that affects server state or resources.
    info
    General information that outlines overall task progress.
    config
    Configuration change or status.
    detail
    General information that details subtask progress.
    fine
    General trace information, includes method entry, exit, and return values.
    finer
    Detailed trace information.
    finest
    A more detailed trace that includes all the detail that is needed to debug problems.
    all
    All events are logged. If you create custom levels, 'all' includes those levels, and can provide a more detailed trace than finest.

    When you enable a logging level, you are also enabling all of the levels with higher severity. For example, if you set the logging level to warning on your application server, then warning, severe and fatal events are processed.
  • Trace format: This format is used for the trace log. Valid values are BASIC, TBASIC, ENHANCED, or ADVANCED. The TBASIC and ADVANCED formats are equivalent to what is used in the WebSphere Application Server traditional. TBASIC is also an alias for the BASIC format.
The following examples show sample output in each of the available log formats and list the logs for which each format is available: SIMPLE, JSON, TBASIC, ENHANCED, and ADVANCED.
SIMPLE (messages logs)
[18/10/21 14:49:26:246 EDT] 0000003e com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 7.844 seconds
JSON (messages logs)
{"type":"liberty_message","host":"HOST","ibm_userDir":"/wlp\/usr\/","ibm_serverName":"defaultServer","message":"CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 7.967 seconds.","ibm_threadId":"0000003e","ibm_datetime":"2021-10-18T14:50:58.159-0400","ibm_messageId":"CWWKF0011I","module":"com.ibm.ws.kernel.feature.internal.FeatureManager","loglevel":"AUDIT","ibm_sequence":"1634583058159_0000000000009"}
TBASIC (messages and trace logs)
[18/10/21 14:47:19:718 EDT] 0000003e FeatureManage A   CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 7.718 seconds.
ENHANCED (trace logs)
[26/10/21 10:42:42:300 EDT] 0000006d id=00000000 x.com.ibm.ws.collector.manager.buffer.BufferManagerImpl      3 Adding event to buffer GenericData
[type=com.ibm.ws.logging.source.trace,ibm_datetime=1635259362300,ibm_messageId=null,ibm_threadId=109,module=com.ibm.ws.event.internal.EventImpl,severity=
<,loglevel=EXIT,ibm_methodName=setProperty,ibm_className=null,levelValue=400,threadName=Framework stop - Equinox Container: 2005505a-a1d7-46dc-abdd-
7230d055f81e,correlationId=,org=,product=,component=,message=Exit ,objectId=-964551509]
ADVANCED (trace logs)
[26/10/21 10:29:25:011 EDT] 00000073  > UOW= source=com.ibm.ws.event.internal.EventImpl method=setProperty id=5f05cd40 org= prod= component=
          Entry
          service.objectClass
          java.util.concurrent.ExecutorService
          com.ibm.wsspi.threading.WSExecutorService
When the message format is set to JSON logging, you can indicate message sources that route to the messages.log file. Valid values are message, trace, accessLog, and ffdc. The following examples show sample output for each of the sources.
Message event
{
    "type":"liberty_message",
    "host":"9e1eceec70c1",
    "ibm_userDir":"\/opt\/ol\/wlp\/usr\/",
    "ibm_serverName":"defaultServer",
    "message":"BADAP0004W: BadApp Angry for test",
    "ibm_threadId":"0000009f",
    "ibm_datetime":"2020-05-04T12:33:26.064+0000",
    "ibm_messageId":"BADAP0004W",
    "module":"com.ibm.ws.lumberjack.badness.Angry",
    "loglevel":"WARNING",
    "ibm_methodName":"doGet",
    "ibm_className":"Angry",
    "ibm_sequence":"1588595606064_0000000000024",
    "ext_thread":"Default Executor-thread-108"
}
Trace event
{
    "type":"liberty_trace",
    "host":"9e1eceec70c1",
    "ibm_userDir":"\/opt\/ol\/wlp\/usr\/",
    "ibm_serverName":"defaultServer",
    "message":"BadApp Angry test",
    "ibm_threadId":"0000009f",
    "ibm_datetime":"2020-05-04T12:33:26.066+0000",
    "ibm_messageId":"BADAP0001W",
    "module":"com.ibm.ws.lumberjack.badness.Angry",
    "loglevel":"FINE",
    "ibm_methodName":"doGet",
    "ibm_className":"Angry",
    "ibm_sequence":"1588595606066_0000000000001",
    "ext_thread":"Default Executor-thread-108"
}
FFDC event
{
    "type":"liberty_ffdc",
    "host":"252ecfa1f755",
    "ibm_userDir":"\/opt\/ibm\/wlp\/usr\/",
    "ibm_serverName":"defaultServer",
    "ibm_datetime":"2020-03-24T19:08:14.579+0000",
    "message":"A metric named   com.acmeair.web.AuthServiceRest.com.acmeair.web.AuthServiceRest.login with tags app=\"acmeair-authservice-java\" already exists",
    "ibm_className":"com.ibm.ws.microprofile.metrics.impl.MetricRegistryImpl",
    "ibm_exceptionName":"java.lang.IllegalArgumentException",
    "ibm_probeID":"656",
    "ibm_threadId":"00000275",
    "ibm_stackTrace":"java.lang.IllegalArgumentException: A metric named com.acmeair.web.AuthServiceRest.com.acmeair.web.AuthServiceRest.login with tags app=\"acmeair-authservice-java\" already exists\n\tat ...",
    "ibm_objectDetails":"Object type = com.ibm.ws.microprofile.metrics.impl.MetricRegistryImpl\n  metrics = class java.util.concurrent.ConcurrentHashMap@f445b6cd\n...",
    "ibm_sequence":"1585076894579_0000000000001"
}
HTTP access event
{
    "type":"liberty_accesslog",
    "host":"79e8ad2347b3",
    "ibm_userDir":"\/opt\/ibm\/wlp\/usr\/",
    "ibm_serverName":"defaultServer",
    "ibm_remoteHost":"172.27.0.10",
    "ibm_requestProtocol":"HTTP\/1.1",
    "ibm_userAgent":"Apache-CXF/3.3.3-SNAPSHOT",
    "ibm_requestHeader_headername":"header_value",
    "ibm_requestMethod":"GET",
    "ibm_responseHeader_connection":"Close",
    "ibm_requestPort":"9080",
    "ibm_requestFirstLine":"GET \/favicon.ico HTTP\/1.1",
    "ibm_responseCode":200,
    "ibm_requestStartTime":"2020-07-14T13:28:19.887-0400",
    "ibm_remoteUserID":"user",
    "ibm_uriPath":"\/favicon.ico",
    "ibm_elapsedTime":834,
    "ibm_accessLogDatetime":"2020-07-14T13:28:19.887-0400",
    "ibm_remoteIP":"172.27.0.9",
    "ibm_requestHost":"172.27.0.9",
    "ibm_bytesSent":15086,
    "ibm_bytesReceived":15086,
    "ibm_cookie_cookiename":"cookie_value",
    "ibm_requestElapsedTime":3034,
    "ibm_datetime":"2020-07-14T13:28:19.887-0400",
    "ibm_sequence":"1594747699884_0000000000001"
}
If the message format is set to JSON logging, and the application writes a pre-formatted JSON message to standard out or standard error, the pre-formatted JSON message is written to the log without modification.  If the message that is written is not JSON, the application server embeds the message into the message field of a liberty_message event.  A JSON message that is written to standard out or standard error must not include unencoded formatting characters such as newline characters in order to be written to the log without modification.

Why use it?

You can simplify log parsing by producing your logs in JSON format. JSON is a self-describing format that many log analysis tools can consume without requiring format-specific parsing instructions.
 

Availability

The support is enabled in the following HTTP group PTFs and PTFs:

V7R3M0 SF99722 Level 38
V7R4M0 SF99662 Level 19

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"HW1A1","label":"IBM Power Systems"},"Component":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
27 March 2022

UID

ibm16566803