Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

how logging works in AEM for java source code

Avatar

Avatar
Ignite 10
Level 4
TB3dock
Level 4

Likes

34 likes

Total Posts

203 posts

Correct Reply

4 solutions
Top badges earned
Ignite 10
Boost 25
Give Back 25
Validate 10
Validate 1
View profile

Avatar
Ignite 10
Level 4
TB3dock
Level 4

Likes

34 likes

Total Posts

203 posts

Correct Reply

4 solutions
Top badges earned
Ignite 10
Boost 25
Give Back 25
Validate 10
Validate 1
View profile
TB3dock
Level 4

05-04-2021

There are several reference pages for configuration of various different logging systems in AEM (e.g. this and this) , but I cant find anything on how to create/inject and use them.  

In the wknd project, we see this:

 

 

private static final Logger log = LoggerFactory.getLogger(ImageListImpl.class);
:
log.warn("Could not locate the AEM WCM Core Components List SlingModel via this component's ResourceSuperType. Returning an empty list.");

 

 

Is this best practice?  It seems to be using slf4j.  Is this the AEM system wide default?
What logging injection/usage do people recommend?
How do we switch log levels etc?  Can this be done at run time?
 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 2
salamswapnil
Level 2

Likes

6 likes

Total Posts

16 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 2
salamswapnil
Level 2

Likes

6 likes

Total Posts

16 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back
Ignite 1
Boost 5
Boost 3
View profile
salamswapnil
Level 2

05-04-2021

Hi @TB3dock 

 

Yes, the snippet you have shared is the standard practice for logging and it's slf4j.

You can create logs specific to your application and change its level here.

You can find more info about logging here: 

https://experienceleague.adobe.com/docs/experience-manager-64/deploying/configuring/configure-loggin...

 

Thanks

Swapnil 

Answers (1)

Answers (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

551 likes

Total Posts

663 posts

Correct Reply

191 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

551 likes

Total Posts

663 posts

Correct Reply

191 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

05-04-2021

Hi @TB3dock 

You are already referring the correct documents for AEM Logs.

https://experienceleague.adobe.com/docs/experience-manager-65/deploying/configuring/configure-loggin...

http://www.sgaemsolutions.com/2017/04/aem-logs-in-detail-part-1.html

http://www.sgaemsolutions.com/2019/12/aem-logs-in-detail-part-2.html

https://experienceleague.adobe.com/docs/experience-manager-64/administering/operations/troubleshooti...

https://www.royalcyber.com/blog/portal/custom-logging-with-aem-logger/

 

By default AEM uses slf4j log support and it's recommended by Adobe as well.

 

Log levels can be updated using "Apache Sling Logging Logger Configuration" which is a factory configuration and can be configured based on the need.

 

<?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/something.log"
org.apache.sling.commons.log.level="debug"
org.apache.sling.commons.log.names="[com.something.abc.core]"
org.apache.sling.commons.log.pattern="\{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"/> 

 

Hope this helps!

Thanks!