Log levels and Custom Log File in AEM

In AEM (Adobe Experience Manager), logging can be configured to help diagnose issues and monitor system performance. AEM uses the SLF4J (Simple Logging Facade for Java) framework for logging, which provides a consistent interface for logging that can be used with different logging implementations.

There are five standard log levels in AEM:

  1. ERROR – Used for critical errors that require immediate attention.
  2. WARN – Used for warnings that indicate potential problems.
  3. INFO – Used for informational messages that provide status updates.
  4. DEBUG – Used for debugging information that can help diagnose issues.
  5. TRACE – Used for detailed tracing information.

You can configure log levels for different loggers in AEM. Each logger can have its own log level, and logs can be directed to different appenders (such as the console or a custom log file) based on their log level.

To configure logging in AEM, you can use the AEM Web Console. Here are the steps to configure logging to a custom log file:

  1. Log in to the AEM Web Console (http://localhost:4502/system/console/configMgr) with administrative privileges.
  2. Search for the “Apache Sling Logging Configuration” configuration and click on it.
  3. Scroll down to the “Logger Configuration” section and click “Add”.
  4. In the “Logger Name” field, enter the name of the logger you want to configure (for example, “com.example.mylogger”).
  5. In the “Log Level” field, select the log level you want to use for this logger (for example, “DEBUG”).
  6. In the “Appender Name” field, enter the name of the appender you want to use for this logger (for example, “mycustomlog”).
  7. Click “Save” to save your changes.
  8. Scroll down to the “Appender Configuration” section and click “Add”.
  9. In the “Appender Name” field, enter the name of the appender you want to configure (for example, “mycustomlog”).
  10. In the “Appender Class” field, enter the class name of the appender you want to use (for example, “org.apache.log4j.RollingFileAppender”).
  11. In the “Log File” field, enter the path to the custom log file you want to use (for example, “/opt/aem/logs/mylog.log”).
  12. Click “Save” to save your changes.

After configuring the logger and appender, you can use the logger in your AEM code to log messages to the custom log file. For example, you can use the following code to log a message:

Logger logger = LoggerFactory.getLogger("com.example.mylogger");
logger.debug("This is a debug message");

This will log the message “This is a debug message” to the custom log file specified in the appender configuration.

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial