Log ouput in JSON

Our Kibana experts recommend logging in JSON to get better features in monitoring and visualization.
Any possibility XP could support that?

I was (inspired by this post Log output in JSON) able to get following format *1 when logging by adding following dependencies to the /enonic-xp/lib classpath

And changing $xp_home/config/logback.xml

<?xml version="1.0"?>
<configuration scan="true" scanPeriod="60 seconds">

<appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
        <jsonFormatter
            class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
            <prettyPrint>true</prettyPrint>
        </jsonFormatter>
        <timestampFormat>yyyy-MM-dd' 'HH:mm:ss.SSS</timestampFormat>
    </layout>
</appender>
 
  <root level="info">
    <appender-ref ref="JSON"/>
    <appender-ref ref="FILE"/>
  </root>

</configuration>

*1 logging format in json

xp2.local | }{
xp2.local |   "timestamp" : "2020-08-06 11:27:18.959",
xp2.local |   "level" : "INFO",
xp2.local |   "thread" : "cluster-check-thread",
xp2.local |   "logger" : "Events.Service.com.enonic.xp.server.deploy",
xp2.local |   "message" : "ServiceEvent REGISTERED [com.enonic.xp.server.internal.deploy.StoredApplicationsDeployer]",
xp2.local |   "context" : "default"
xp2.local | }{
xp2.local |   "timestamp" : "2020-08-06 11:27:18.967",
xp2.local |   "level" : "INFO",
xp2.local |   "thread" : "cluster-check-thread",
xp2.local |   "logger" : "Events.Service.com.enonic.xp.core.schema",
xp2.local |   "message" : "ServiceEvent REGISTERED [com.enonic.xp.schema.content.ContentTypeService]",
xp2.local |   "context" : "default"
xp1.local | }{
xp1.local |   "timestamp" : "2020-08-06 11:27:18.974",
xp1.local |   "level" : "INFO",
xp1.local |   "thread" : "cluster-check-thread",
xp1.local |   "logger" : "Events.Service.com.enonic.xp.admin.impl",
xp1.local |   "message" : "ServiceEvent REGISTERED [com.enonic.xp.admin.widget.WidgetDescriptorService]",
xp1.local |   "context" : "default"
xp1.local | }{
xp1.local |   "timestamp" : "2020-08-06 11:27:18.975",
xp1.local |   "level" : "INFO",
xp1.local |   "thread" : "cluster-check-thread",
xp1.local |   "logger" : "Events.Service.com.enonic.xp.core.app",
xp1.local |   "message" : "ServiceEvent REGISTERED [com.enonic.xp.descriptor.DescriptorService]",
xp1.local |   "context" : "default"
xp1.local | }
4 Likes

As @rf0 demonstrates this is possible right now. We are unsure why you need the dependencies and we will look into this.

Note: There is no more details in the log if the format is JSON.

1 Like