Expand my Community achievements bar.

SOLVED

How to Implement loggers for debuging

Avatar

Level 3

Dear Community,

I have a sampleToolboxConfigurationPresenter class for my Toolbox configuration, as below:

public class sampleToolboxConfigurationPresenter extends samplePresenter {

    private final Dao<sampleToolboxConfigurationDto> dao = new GenericSlingDao<sampleToolboxConfigurationDto>(sampleToolboxConfigurationDto.class);

    /** {@inheritDoc} */

    @Override

    public sampleToolboxConfigurationModel getModelFromResource(SlingHttpServletRequest request,Resource resource) {

        sampleToolboxConfigurationDto dto = dao.getDtoOrNewOnError(resource);

        return new sampleToolboxConfigurationModel(dto);

    }

}

Could you please let me know In The above code How can I get the attributes of  dto by using the loggers .And how can I use the loggers for debuging.

1 Accepted Solution

Avatar

Correct answer by
Level 10

It should state in the AEM docs that you need to go here: 

http://localhost:4502/system/console/configMgr

Look for Apache Sling Logging Configuration - as shown here: 

Hope this helps

View solution in original post

7 Replies

Avatar

Level 10

To log messages in AEM - you simply create an instance of http://www.slf4j.org/api/org/slf4j/Logger.html:

/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());

then write out what you want: 

log.debug("This will log out");

See this community article that logs messages: 

https://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html

Avatar

Level 4

Hi Scott,

Thanks for your quick reply.

I added the log in my SampleToolboxConfigurationPresenter class file, as shown below.

public class SampleToolboxConfigurationPresenter extends AbstractPresenter {
    
    protected final Logger LOG = LoggerFactory.getLogger(this.getClass());

    private final Dao<SampleToolboxConfigurationDto> dao = new GenericSlingDao<SampleToolboxConfigurationDto>(
            SampleToolboxConfigurationDto.class);

    /** {@inheritDoc} */
    @Override
    public SampleToolboxConfigurationModel getModelFromResource(SlingHttpServletRequest request,
            Resource resource) {
        
        LOG.debug("This will log out");
        LOG.info("Temperature has risen above 50 degrees.");
        
        SampleToolboxConfigurationDto dto = dao.getDtoOrNewOnError(resource);
        return new SampleToolboxConfigurationModel(dto);
    }
    
   
}

But I am not bale to see my log entry in any of the files.

access.log , history.log , request.log

Thanks,

Sonu

Avatar

Level 10

Its error.log - that is where its written too. 

Avatar

Level 9

Have you changed Logger log mode?. You should change it to debug mode from OSGI config to get debug message in log file.

https://docs.adobe.com/docs/en/aem/6-1/deploy/configuring/configure-logging.html

--

Jitendra

Avatar

Level 4

Hi Jitendra,

I did not changed Logger log mode?.

You should change it to debug mode from OSGI config to get debug message in log file.

https://docs.adobe.com/docs/en/aem/6-1/deploy/configuring/configure-logging.html

I followed the adobe document but did not understand much.

Could you please send me the screenshot, how can I change it in OSGI config.

 

Thanks,

Sunita 

Avatar

Correct answer by
Level 10

It should state in the AEM docs that you need to go here: 

http://localhost:4502/system/console/configMgr

Look for Apache Sling Logging Configuration - as shown here: 

Hope this helps