Tejas
Tejas

Reputation: 13

AEM custom logs creation from scripts

we are automating the AEM configurations, we have a requirement for creating a custom log file. current Manual step followed is login to AEM Felix console -> Sling -> log support ->Add new logger parameters updated are log level, log file and logger.

is there a way to automate this log creation ? Please share your inputs.

Thanks in advance,

Upvotes: 0

Views: 1429

Answers (1)

Shawn
Shawn

Reputation: 9402

You can do this by configuring OSGI content nodes or by creating OSGI config files. For instance, I created an OSGI config node at this location:

/apps/cq/config.publish/org.apache.sling.commons.log.LogManager.factory.config-util.xml

That file has contents such as this:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:OsgiConfig"
    org.apache.sling.commons.log.file="logs/util.log"
    org.apache.sling.commons.log.level="debug"
    org.apache.sling.commons.log.names="[com.myorg.commons.util.MyUtil,com.myorg.commons.util.OtherUtil]"
    org.apache.sling.commons.log.pattern="\{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"/>

Similarly, you can also do this for

/apps/cq/config.publish/org.apache.sling.commons.log.LogManager.factory.writer-util.xml

With contents such as

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:OsgiConfig"
    org.apache.sling.commons.log.file="logs/util.log"
    org.apache.sling.commons.log.file.buffered="{Boolean}false"
    org.apache.sling.commons.log.file.number="5"
    org.apache.sling.commons.log.file.size="20MB"/>

See https://helpx.adobe.com/experience-manager/6-3/sites/deploying/using/configuring-osgi.html for more details on how these files can be made specific to run modes.

When you install the package containing these nodes, since they are jcr:primaryType of sling:OsgiConfig they will automatically be picked up and configured in your environment (per run mode matching).

Upvotes: 0

Related Questions