Expand my Community achievements bar.

Two or more custom logs - AEM

Avatar

Community Advisor

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?

1478125_pastedImage_7.png

Can you someone help me to understand this?

Thanks

21 Replies

Avatar

Level 10

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

Avatar

Community Advisor

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

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

Avatar

Community Advisor

Thanks Scott! We have already configured the custom log and looking to configure second custom log.

Using 2 logs is not documented in any doc or article. I am checking internally.

Avatar

Community Advisor

Hi Noksc

    When I implement multiple logs I make sure it is pointing to two seperate packages. As I can see ur customlog1 is parent package of customlog2. So it is pretty obvious that anything under com.geometrixx.aem.core.newfunctionality will be specifically written to your second log as it is more precise.

Lets say you need to log a particular class logs to separate log, then you shud create a customlog with that class path .

In your case, the second log is more precise and anything inside the above package will be printed in your second log.

Thanks

Veena

Avatar

Community Advisor

Hi Veena_07,

Thanks for your explanation. I am assuming that all the classes under com.geometrixx.aem.core.newfunctionality should send the logs to both custom logs. However, they are logging only to custom-log2.log. I didn't find any doc on how logger selects the particular log file to log the messages.

Thanks.

Avatar

Level 1

Hi Veen,

 

If i have two packages pack1 and pack2 in crx/de, how do i get logs from pack1 and pack2?

 

Please provide any example.

 

Thanks,

Ramkrishna

Avatar

Community Advisor

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.

Avatar

Community Advisor

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.

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

Hi, The Apache Sling Logging Logger Configuration says this in the description: "The logger names applicable for this logger configuration. Each logger name applies for any child category unless configured otherwise. E.g. a logger name of org.apache.sling applies to logger org.apache.sling.commons unless there is a different configuration for org.apache.sling.commons. (org.apache.sling.commons.log.names)"

Also, the LogConfigManager.java file says "The logger names to which this configuration applies. As logger names form a hierarchy like Java packages, the listed names also apply to "child names" unless more specific configuration applies for such children. This property may be a single string, an array of strings or a collection of strings. Each string may itself be a comma-separated list * of logger names. If this property is missing a * <code>ConfigurationException</code> is thrown."

Hope this helps!

Avatar

Level 10

Veena contributed a nice artilce that we will release in a day or two. It shows how to setup a custom log file and even bind it to a package resulting in different Java packages in a project writing to different files. Keep you eye on the 2018 Community Articles list pinned at top.

Avatar

Level 10

It looks like you can build log files and then bind them to different Java packages. For example - see this which writes out logging in:

com.aem.logsample.core.models.HelloWorldModel

Props2.png

If you put in two nodes for the same Java package, it will only write to the 1st one. So you can use two log files - as long as they are bound to different Java packages.

Avatar

Community Advisor

Thanks Scott! I've tried the same approach but I had question of how the specific logger is getting selected but Veena and Rima replies answers my question.

Thanks again.

My observations are based on Veena' s draft - see here: https://onedrive.live.com/view.aspx?ref=button&Bsrc=SMIT&resid=30E6F3F3DE5129F6!544&cid=30e6f3f3de51...

We are converting this to a Community article so ppl will not run into this again. This is what community is all about!

Avatar

Employee Advisor

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

Avatar

Level 10

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