Can we log from Sightly / HTL? | Community
Skip to main content
Employee
January 22, 2017
Solved

Can we log from Sightly / HTL?

  • January 22, 2017
  • 4 replies
  • 4046 views

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.
Best answer by Feike_Visser1

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
August 26, 2017

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

}

smacdonald2008
New Participant
January 23, 2017

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

Feike_Visser1
Feike_Visser1Accepted solution
Employee
January 23, 2017

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

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

smacdonald2008
New Participant
January 22, 2017

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