Search code examples
javaaem

Getting Dependency Issues and How to Create a Logger File for Specific Classes in AEM?


enter image description hereI'm currently facing difficulties adding logger files for a specific Java class in AEM, and I'm unable to obtain the logger object due to missing dependencies. I'm uncertain about the appropriate steps to resolve this within the AEM environment. Can you guide me on how to correctly configure the logger for a specific class, considering the issue with missing logger object dependency?


Solution

  • Follow the following steps

    1. Check if the required dependencies are included in your Maven pom.xml file. If any dependencies are missing, you can add them to ensure the proper functioning of your project.

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>{slf4j-version}</version> 
    </dependency>
    

    2. Import the package

    import org.slf4j.Logger;

    3. Provide proper syntax for logger object creation

    private static final Logger logger = LoggerFactory.getLogger(YourClass.class);

    4. Access the LogSupport page in your web console by navigating to http://localhost:4502/system/console/slinglog.

    • Click on the "Add new logger" button to create a new logging configuration.
    • Specify the desired log levels (such as Info, Debug, etc.) in the Logger Levels section according to your requirements.
    • Decide on the "Additive" setting based on whether you want the new logger's configuration to be combined with (true) or completely override (false) its parent logger's configuration.
    • Optionally, define a custom log file path (e.g., logs/customName.log) in the Logger File section, or keep the default file.
    • In the Logger section, provide either a class path from your application's classes or a package path to configure logging at the class or package level, respectively.

    You can directly inspect the log files in the crx-quickstart/logs directory to view all the logger files present. You can use a text editor or command-line tools to access these logs. Once you locate your logger's created file, you can open it to view the logger messages.