AEM 6.3 Customize log message using appender and slf4j | Community
Skip to main content
Level 2
Sep 13, 2018 11:01 PM UTC
Solved

AEM 6.3 Customize log message using appender and slf4j

In our AEM 6.3 project, we have a need to add the additional attribute in log message. Basically, we want to customize the message format. So we have created one logback file under src/main/resources/logback.xml. Content of the logfile is as follows

<configuration>  <appender name="SampleProject.log" class="ch.qos.logback.core.FileAppender"> <file>SampleProject.log</file> \<append>true</append> <encoder> <pattern>%d %-5level %X{sling.userId:-NA} [%thread] %logger{30} %marker- %msg %n</pattern> <immediateFlush>true</immediateFlush> </encoder> </appender>  <logger name="org.wc.project" level="INFO"/>  </configuration>

And under Apache Sling Logging Configuration, we have created one log configuration as follows with "same name" as appender name.

org.apache.sling.commons.log.file="SampleProject.log" org.apache.sling.commons.log.level="info" org.apache.sling.commons.log.logger.paatern ="org.wc.project" org.apache.sling.commons.log.pattern="{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}" 

But the customized message format is now shown in SampleProject.log. Can anybody please provide any pointers for the same.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
Sep 16, 2018 6:55 PM UTC

Check the Sling documentation for it (Apache Sling :: Logging ).

Jörg

4 replies

joerghoh
joerghohAccepted solution
Employee
Sep 16, 2018 6:55 PM UTC

Check the Sling documentation for it (Apache Sling :: Logging ).

Jörg

Translate
arunpatidar
New Participant
Sep 14, 2018 5:51 PM UTC

for MDC you can find more info at https://logback.qos.ch/manual/mdc.html

I've never tried customising logs so not sure how you can extend OOTB logging.

Translate
Arun Patidar
Level 2
Sep 14, 2018 4:09 PM UTC

Sling MDC Inserting Filter exposes various request details as part of MDC. But in my case, I need additional variables like Application Name, Application Version etc. MDC is limited to pre-defined variables, so how to add the custom variables in log?

Translate
arunpatidar
New Participant
Sep 14, 2018 9:33 AM UTC

Hi,

I am not sure with Appender you can dump customise log in to project log file or you can specify same log file for appender as well.

You can check Slf4j MDC log option as well if helps

Apache Sling :: Logging

Translate
Arun Patidar