Search code examples
aemaem-6

How do I use a logger in a script used in data-sly-use in AEM?


Data sly use is used for helper classes this could either be a Java WCMUsePojo or a server side Javascript .

How do I use a logger in a server side script eg. data-sly-use.nav="nav.js" ?


Solution

  • HTL comes with a set of global objects that are ready to be used in server side JS. One of these objects is the log object which exposes an implementation of org.slf4j.Logger

    You can use it like the example below in your code:

    log.info("some info");
    

    More details can be found in the official documentation which also details out a lot of other helpful objects available in the same context.