Convert log outputs to JSON formatting

If you want to ingest your log outputs into a third-party log consumer, such as Elasticsearch, you can convert DQ logs to JSON formatting. This page shows you how to convert DQ logs to JSON formatting.

Steps

  1. Open the dq-web folder and then open the log4j2.xml file.
  2. In the <Appenders> section, look for the following line of code:
  3. <PatternLayout pattern="%d{yy/MM/dd HH:mm:ss.SSS} %X{sessionId} %X{sessionHost} %X{userName} [%t] %-5level %logger{36} - %m{nolookups}%n"/>

  4. Comment out the <PatternLayout section with the following <JsonLayout to convert the output from Pattern to JSON:
  5. <!--<PatternLayout pattern="%d{yy/MM/dd HH:mm:ss.SSS} %X{sessionId} %X{sessionHost} %X{userName} [%t] %-5level %logger{36} - %m{nolookups}%n"/>-->
    <JsonLayout objectMessageAsJsonObject="true" complete="false" eventEol="true" compact="true" properties="true" includeTimeMillis = "true"></JsonLayout>

    Note You can remove the <!-- ... --> from the commented out line of code to revert from the JsonLayout to the PatternLayout format.

  6. Set the compact= attribute to one of the following options:
    1. compact="true" for compact JSON payloads.
    2. compact="false" for decompressed JSON payloads.
  7. Optionally review the other attributes in the JSON layout.
  8. Attribute Data Type Description
    complete boolean

    When set to true, the appender includes the JSON header and footer. Records are comma-delimited.

    The default value is false.

    includeTimeMillis boolean When set to true, the appender includes the timeMilis attribute in the JSON payload instead of the instant. timeMillis contains the number of milliseconds since January 1, 1970 at midnight UTC.
    objectMessageAsJsonObject boolean

    When set to true, ObjectMessage is serialized as JSON object to the message field of the output log.

    The default values is false.

    compact boolean

    When set to true, the appender does not use end-of-lines or indentation.

    The default value is false.

    eventEol boolean

    When set to true, the appender appends an end-of-line after each record.

    The default value is false.

    To see one record per line, set both eventEol="true" and compact="true".

    properties boolean

    When set to true, the appender includes the thread context map in the generated JSON.

    The default value is false.

    includeStacktrace boolean

    Optional. When set to true, the appender includes full stacktrace of any logged Throwable.

    The default value is true.

Tip You can optionally keep both the JSON and Pattern layouts by writing logs in a different file.