AEM JavaScript Use-API

Tips and resources for using AEM’s Sightly / HTL JavaScript Use-API for writing server-side JavaScript. The AEM JavaScript Use-API ResourceUtils page contains examples for using ResourceUtils and functions.

part II - AEM JavaScript Use-API ResourceUtils

Debugging / Logging

Debugging is essential to development, especially when trying to learn what JavaScript patterns, variables, etc. can be utilized within the Use-API.

Custom Log File

Navigate to the Web Console and select Sling: Log Support. e.g., http://localhost:4502/system/console/slinglog

  1. Select Add new Logger,

  2. Select DEBUG for the log level, e.g., Log Level: DEBUG;

  3. Enter a log file path, e.g., Log File: logs/debug.log

  4. Enter a path for the Logger, e.g., apps

  5. Select the Save button

Adobe Experience Manager Web Console Log Support | Add new Logger

Create a server-side JavaScript file to test the logger.

In crx/de, e.g., http://localhost:4502/crx/de

expand apps/weretail/components/structure right-click page and select Create > Create File

name the file, e.g., example.js and add the following Use-API code:

"use strict";

use( function() {

  log.debug('### TESTING');  


Edit /apps/weretail/components/structure/page/body.html and add a sly element to use the server-side JavaScript file. e.g.,

<div class="container">

    <sly data-sly-use.test="${'example.js'}"></sly>

Load the URL to test the file, for example, http://localhost:4502/content/we-retail/us/en.html

Read the log file

This example shows how to tail the log in a terminal session. Use tail to monitor log files in real time. The -n300 argument show the last 300 lines. The default is only 10 lines.

cd /opt/aem/author/crx-quickstart/logs

tail -n300 -f debug.log

Use the tail command with the -f argument to follow the content of a file. Use the -F argument to follow the creation of a new log.

This example shows how to return only log entries for a specific Use-API class.

tail -f debug.log | grep {Use Class name}

If you want to use the a web browser to view the log file, open the Log Tail endpoint to read the last 1000 lines of the custom log file, for example:



comments powered by Disqus