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.");
Solved! Go to Solution.
Views
Replies
Total Likes
Thanks! I see there is a line for com.adobe.aem.guides.wknd, to allow the level to change.
Views
Replies
Total Likes
Hi @TB3dock
You are already referring the correct documents for AEM Logs.
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://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!
Logging in AEM (Adobe Experience Manager) for Java source code can be achieved using the SLF4J (Simple Logging Facade for Java) API.
Here are the steps to configure logging in AEM:
1. Add the SLF4J API and a logging implementation JAR to your AEM project's dependencies. The most commonly used logging implementations are Logback and Log4j.
2. Create a logback.xml or log4j.properties file in the project's classpath. These files contain the logging configuration details such as log levels, appenders, etc.
3. Add the logging statements in your Java source code using the SLF4J API. For example:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyClass {
private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
public void myMethod() {
LOGGER.debug("Debug message");
LOGGER.info("Info message");
LOGGER.warn("Warn message");
LOGGER.error("Error message");
}
}
Deploy the AEM project and monitor the log files for the output of the logging statements.
By default, AEM uses the Log4j logging framework. You can configure AEM's logging settings using the OSGi configuration console. In the console, you can set the log levels and appenders for various AEM components and modules. The console can be accessed via the URL http://localhost:4502/system/console/configMgr .
It's important to properly configure the logging statements to avoid performance issues, such as unnecessary logging and excessive log volume. Properly logging important information and errors can help diagnose issues and debug problems that occur in the application.
Views
Replies
Total Likes
Thank you for the detailed explanation on logging in AEM using SLF4J. The step-by-step guide is really helpful, especially for ensuring proper logging setup and avoiding performance pitfalls. I appreciate the insight into configuring the logging framework via the OSGi console, and I'll be sure to keep log levels and volume in mind to maintain efficient logging practices.
This will definitely help in setting up a robust logging mechanism in our AEM projects. Thanks again for the valuable information!
Views
Replies
Total Likes
Hi Swapnil,
Thank you for confirming that the snippet follows standard logging practices using SLF4J.
I appreciate the information on customizing logs specific to my application and adjusting their levels.
For further details, I will refer to the provided link on configuring logging in Adobe Experience Manager.
Thanks again!
Best regards,
Views
Likes
Replies