Expand my Community achievements bar.

SOLVED

Can we log from Sightly / HTL?

Avatar

Employee

Looking at the list of HTL Global Objects in the documentation log is listed as a java-backed object backed by org.slf4j.Logger.

My question is, how can I use it?

I can't find any examples of it.

Thinking about it, this is a specific case of a more general question; How can I call methods and pass parameters to Java-backed objects?

I know it can be done when instantiating a Use-API object but that's not the pattern I'm after.

If it can't be done then it is hard to understand why the log and out objects are made available.

1 Accepted Solution

Avatar

Correct answer by
Employee

You can't specify arguments like ${log.info("hello")}

You can only make log statements via Java or JS code.

View solution in original post

4 Replies

Avatar

Level 10

As stated in the docs - the log corresponds to the Java object. So you would use it in the front end like you would use it in the Java backend. ie

Java:

log.info("") ; 

Front end : 

"${log.info("")}

I have only used logging in back end - but this should work according to the docs. Also HTL spec here: 

https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md

Avatar

Correct answer by
Employee

You can't specify arguments like ${log.info("hello")}

You can only make log statements via Java or JS code.

Avatar

Level 10

We will ensure that this fact is placed into the AEM docs. 

Avatar

Community Advisor

Adding to the Visser Statement

In Javascript which we call via sightly script add logs like

use(function() { log.error(“Log from Sightly JS Code");}

In Java Code

private final Logger log = LoggerFactory.getLogger(MyCustomClass.class);

private void mymethod(){

log.info("Event Path===>{}",evnt.getPath());

}