Two or more custom logs - AEM | Community
Skip to main content
Singaiah_Chintalapudi
Level 7
May 2, 2018 12:21 PM UTC

Two or more custom logs - AEM

Hi,

Currently, we have a custom log name (org.apache.sling.commons.log.LogManager.factory.config-customLog1): custom-log1.log and logging all the details for: com.gemotrixx.aem

I have created another logger (org.apache.sling.commons.log.LogManager.factory.config-customLog2) name is: custom-log2.log and logging com.geometrixx.aem.core.newfunctionality details.

When I run the new functionality, it should log details to both logs but its logging into only the second log.

I am getting the logger : Logger log = LoggerFactory.getLogger(getClass());

Can we get a specific logger instance to log the details as mentioned in below post?

Can you someone help me to understand this?

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

21 replies

joerghoh
Employee
May 2, 2018 8:42 PM UTC

The same log statements can go into 2 different logfiles. I just tested this in AEM 6.3 SP2, but it's likely there already for a while (although not really mentioned). The best way to find out if it's present is to to use the Sling Log console at localhost:4502/system/console/slinglog

When you create your logger via configuration, you have to set the "additiv" flag. For example I created a logfile for a caconfig related stuff. The definition in the JCR looks like this (.config notation):

org.apache.sling.commons.log.names=["org.apache.sling.caconfig"]

org.apache.sling.commons.log.file="logs/caconfig.log"

org.apache.sling.commons.log.level="trace"

org.apache.sling.commons.log.additiv="true"

Now when Sling CA-Config logs something it goes both into logs/caconfig.log and logs/error.log.

HTH,

Jörg

Translate
smacdonald2008
Level 10
May 2, 2018 8:46 PM UTC

We will capture Joerg's points too in the new community article. This is really what AEM community is all about - thanks Joerg!

Translate
smacdonald2008
Level 10
May 2, 2018 9:13 PM UTC

With Joergs response - i tested this too setting org.apache.sling.commons.log.additiv.

You can get AEM to log to the default log file (project-logsample) and a custom one (logsample-model.log).

However - still not seeing a way to write out a message to 2 custom log files bound to the same Java package. We will make that note in the article.

Translate
VeenaVikraman
New Participant
May 2, 2018 4:33 PM UTC

No . I don't think that is correct. Since the core.newfunctionality is more precise the classes under that package will send logs to the log2. Others will be logged to log1.

Translate
Singaiah_Chintalapudi
Level 7
May 2, 2018 4:50 PM UTC

Thanks. Can you provide me some documentation to support the above conclusion? We want to log some pretty significantly important stuff and I want to make sure this is the right approach.

Translate
smacdonald2008
Level 10
May 2, 2018 4:53 PM UTC

As of now - there is no documentation on this use case.

Translate
smacdonald2008
Level 10
May 2, 2018 12:42 PM UTC

For information about how logging works within AEM - see  -- Logging

Translate
Singaiah_Chintalapudi
Level 7
May 2, 2018 1:00 PM UTC

It did not explain about the multiple custom logs. This is a general documentation about configuring a custom log.

Translate
smacdonald2008
Level 10
May 2, 2018 1:13 PM UTC

I am seeing no AEM docs that suggests multiple logs can be used.

You can configure AEM to log to custom logs too -- see this community artilce - CQ Logs - CQ Tutorials 

or - Monitoring and Maintaining Your CQ instance

Translate