Is is possible to log in JSON format in AEM 6.5 | Community
Skip to main content
Level 3
October 27, 2025
Question

Is is possible to log in JSON format in AEM 6.5

  • October 27, 2025
  • 2 replies
  • 484 views

Hi,

 

We have a business requirement to log in JOSN format.

we have integrated with Elastic APM, and also configured fleet to view error.log and custom logs, but log format in error.log logs don't really match the Elastic Common Schema, hence we are trying to generate logs in JSON format.

 

As anyone used this JSON Event Logger for the above requirement.

Thanks

2 replies

SantoshSai
Community Advisor
Community Advisor
October 27, 2025

Hi @smrithigo,

Yes, JSON logging is possible in AEM 6.5. Since AEM uses Logback underneath the Sling logger API, you can enable JSON logging by adding a custom Logback configuration and encoder through your codebase. Below are the steps:

Add Logstash Logback Encoder library to your project

(This enables JSON output)

pom.xml

<dependency>
    <groupId>net.logstash.logback</groupId>
    <artifactId>logstash-logback-encoder</artifactId>
    <version>7.3</version>
</dependency>

Deploy this via your AEM project bundle package.

Create / override Logback config

Add file in:

/crx-quickstart/conf/logback.xml

Example JSON logger config:

<configuration>

    <appender name="JSON_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/aem-json.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>logs/aem-json-%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>7</maxHistory>
        </rollingPolicy>

        <encoder class="net.logstash.logback.encoder.LoggingEventEncoder">
            <provider class="net.logstash.logback.composite.loggingevent.LoggingEventPatternJsonProvider">
                <pattern>
                    {"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}", "level":"%level", "logger":"%logger", "message":"%msg"}
                </pattern>
            </provider>
        </encoder>
    </appender>

    <logger name="com.mycompany" level="INFO" additivity="false">
        <appender-ref ref="JSON_LOG"/>
    </logger>

</configuration>

This generates structured JSON logs that Elastic can map to ECS fields.

Logging from code remains unchanged

Use the standard SLF4J API:

private static final Logger log = LoggerFactory.getLogger(MyService.class);
log.info("Customer onboarding started");

JSON formatting will be applied automatically

Deploy & restart AEM

JSON logs will show up under:

crx-quickstart/logs/aem-json.log
Santosh Sai
SmrithiGoAuthor
Level 3
October 27, 2025

thanks for the response @santoshsai .

 

I will try this out and let you know. Could you please let me know where this file 

/crx-quickstart/conf/logback.xml 

will be located in the maven project. Thank you. 

SantoshSai
Community Advisor
Community Advisor
October 27, 2025

@smrithigo 

The logback.xml file does not naturally exist inside the AEM Maven project structure by default.
Instead, it needs to be packaged from your codebase and deployed into AEM under:

/crx-quickstart/conf/logback.xml

Include it in your Maven project

Create the file under your ui.apps module (or a dedicated config module):

ui.apps/src/main/content/jcr_root/apps/<your-project>/config/logback.xml

Then ensure it gets installed under the correct AEM internal path using the filter rule:

<filter root="/crx-quickstart/conf" mode="merge"/>

So when your package deploys, it overlays to:

/crx-quickstart/conf/logback.xml

 

Santosh Sai
ManviSharma
Adobe Employee
Adobe Employee
October 27, 2025

Hi @smrithigo,

Yes, this is definitely possible in AEM 6.5. Since AEM uses Logback internally, you can easily output logs in JSON format by adding a JSON encoder and defining a custom appender.

Here’s the simplest way to achieve it:

1. Add the dependency
Include the Logstash Logback Encoder in your project’s pom.xml:

<dependency>

  <groupId>net.logstash.logback</groupId>

  <artifactId>logstash-logback-encoder</artifactId>

  <version>7.3</version>

</dependency>

 

  1. Create a JSON log appender
    In /crx-quickstart/conf/logback.xml, add:

 

<appender name="JSON" class="ch.qos.logback.core.FileAppender">

  <file>${crx.home}/logs/aem-json.log</file>

  <encoder class="net.logstash.logback.encoder.LogstashEncoder" />

</appender>

 

<logger name="com.mycompany" level="INFO" additivity="false">

  <appender-ref ref="JSON" />

</logger>

  1. Deploy & restart AEM
    Logs for your package will now be written in JSON format under /crx-quickstart/logs/aem-json.log.
  2. Connect with Elastic Agent
    Point your Elastic Agent/Fleet configuration to read this file as JSON. The structured output will map cleanly to ECS fields and can be correlated with Elastic APM.

This is the most lightweight and clean approach — no core AEM changes, only one encoder dependency and one config file update.


Hope this helps.


Regards,
Manvi Sharma

 

 

SmrithiGoAuthor
Level 3
October 28, 2025

thanks @manvisharma for the detailed steps.