Can we log from Sightly / HTL? | Community
Skip to main content
Employee
Jan 22, 2017 12:10 AM UTC
Solved

Can we log from Sightly / HTL?

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Jan 23, 2017 9:10 AM UTC

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

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

4 replies

RajaShankar
New Participant
Aug 26, 2017 4:07 AM UTC

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());

}

Translate
smacdonald2008
Level 10
Jan 23, 2017 1:48 PM UTC

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

Translate
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Jan 23, 2017 9:10 AM UTC

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

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

Translate
smacdonald2008
Level 10
Jan 22, 2017 12:29 AM UTC

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

Translate