Tail logs on AEM As Cloud Service

Tailing logs in AEM (Adobe Experience Manager) is a very basic need that each developer performs in his day to day life. Till AEM 6.5 it was very easy to create custom logging or tailing logs using Sling Log Support because usually all developers have System console access on lower environments. But with introduction of AEM as cloud service developers are no longer have access to System console and the traditional way of accessing logs no longer works on cloud. In this tutorial i will show how we can tail logs using terminal or command prompt on AEM as Cloud Service.

AEM logs are required for multiple troubleshooting and monitoring needs. Adobe Cloud Manager supports accessing AEM as a Cloud Service logs via the Adobe I/O CLI with the Cloud Manager plugin for the Adobe I/O CLI.

Lets see step by step how we can tail logs in AEM as Cloud Service:-

Step 1 : Install the Adobe IO Runtime

npm install -g @adobe/aio-cli

Note :- If Adobe IO is already installed in your machine then running above command will update it to the latest version of Adobe IO. After Adobe IO Runtime is successful install, execute below command and you should see below message.

aio -v

//You will see aio version as shown below
@adobe/aio-cli/10.0.0 darwin-arm64 node-v19.4.0

Note :-If you are using older version of node or brew please follow below steps to upgrade to latest.

// Below command will upgrade your local brew to latest

brew upgrade

// use Node version manager (called n) for it.

sudo npm install -g n

// This will upgrade node version to latest

sudo n latest

// Or you can switch to last stable build instead of latest node 
version using below command

sudo n stable

// Run below command to check version of npm and node

npm - v
node -v

Step 2 : Install & Configure the Adobe IO Cloud Manager CLI Plugin

aio plugins:install @adobe/aio-cli-plugin-cloudmanager

Once Adobe IO Cloud Manager CLI Plugin is successfully installed, then we need to Authenticate Adobe IO CLI to access cloud manager API.

Step 3: Adobe IO CLI Authentication :-

This CLI supports two modes of authentication: Browser-based and Service Account. The key distinction between these is that when using browser-based authentication, the API calls made through the CLI are done as you and use your permissions whereas when using Service Account authentication, a separate service account is needed and that account may have separate permissions than you personally would when logging into the Cloud Manager UI. In general, Service Account authentication should be primarily used in a scripting context where there is no opportunity to authenticate with a browser.

Personally i prefer Browser-Based Authentication because it is more user friendly and easy to use and soon adobe is planning to deprecate JWT approach and move to oAuth based authentication as an alternative to JWT tokens.

So in this tutorial i will proceed with Browser-Based Authentication.

Step 4 : ADOBE IO CLI Browser-Based Authentication:-

Execute below command to start Browser-based authentication.

aio auth:login

Once the authentication is successful , you can close the window and return to terminal. If this is your first time and you have not set any global ORG then you might see below message:-

You are currently in:
1. Org: <no org selected>
2. Project: <no project selected>
3. Workspace: <no workspace selected> 

In order to select the correct ORG for which you want to tail logs , execute below command:-

aio cloudmanager:org:select

Note:- This command will list all the available ORG name to select ORG. Use the Arrow Key to navigate to right option and then press Enter.

Step 5 : Fetch ProgramID to set it as Adobe IO Default Program

There are two ways to fetch the Program ID:-

First Approach :- Navigate to your program in cloud manager UI , the last number is your program ID. “https://experience.adobe.com/#/@my_company/cloud-manager/home.html/program/{PROGRAM_ID}”

Second Approach :- Because i have already authenticated to Adobe CLI, lets use CLI command to fetch this Program ID and set as default. In your terminal execute below command to see all avilable Program list.

 aio cloudmanager:list-programs

After running above command you will see below list of program, copy the program ID from the list

 Program Id Name              Enabled 
 ────────── ───────────────── ─────── 
120990     <My Program Name 1> true
120991     <My Program Name 2> true

Execute below command to set default Program:-

aio config:set cloudmanager_programid <Program_ID>
For example:- aio config:set cloudmanager_programid 120990

Step 6: List your Environments under your Program

Run below command to get complete list of all environments available under your Program ID.

aio cloudmanager:list-environments

After running above command you will see below list of Environments

 Environment Id Name                    Type  Description                  
 ────────────── ─────────────────────── ───── ──────────────────────────── 
 1275650       ankur-cloud-sandbox-QA    dev   This environment is for QA   
 1261491       ankur-cloud-sandbox-stage stage This environment is for Stage                             
 1126502       ankur-cloud-sandbox-dev   dev   Development testing of cloud 

Step 7: List Log files from an Environment

Now lets list all the log files present under our environment.

aio cloudmanager:list-available-log-options <Environment ID>
For Example :- aio cloudmanager:list-available-log-options 1126502

After running above command you will see below list of Environment log files

 Environment Id Service            Name          
 ────────────── ────────────────── ───────────── 
 1126502        preview_dispatcher httpdaccess   
 1126502        preview_dispatcher httpderror    
 1126502        preview_dispatcher aemdispatcher 
 1126502        author             aemaccess     
 1126502        author             aemerror      
 1126502        author             aemrequest    
 1126502        author             cdn           
 1126502        publish            aemaccess     
 1126502        publish            aemerror      
 1126502        publish            aemrequest    
 1126502        publish            cdn           
 1126502        preview_publish    aemaccess     
 1126502        preview_publish    aemerror      
 1126502        preview_publish    aemrequest    
 1126502        preview_publish    cdn           
 1126502        dispatcher         httpdaccess   
 1126502        dispatcher         httpderror    
 1126502        dispatcher         aemdispatcher

Step 8: Tailing Log File

In order to tail desired log files, execute below command:-

aio cloudmanager:tail-log <Environment ID> <Service Name> <Log File Name>
For Example:-
aio cloudmanager:tail-log 1126502 author aemerror

After running above command you will see that your desired logs are now getting tailed:-

21.02.2024 02:20:10.394 [cm-p1234-e10001-aem-author-674d744bf5-q862v] *INFO* [67.189.6.206 [1591669210392] POST /content/dam.initiateUpload.json HTTP/1.1] com.adobe.cq.assetcompute.impl.servlet.InitiateUploadAssetServlet initiate upload asset: Mountain Biking the Uetliberg in Zurich.mp4, size: 74013446, mimeType: video/mp4
21.02.2024 02:20:10.397 [cm-p1234-e10001-aem-author-674d744bf5-q862v] *INFO* [67.189.6.206 [1591669210392] POST /content/dam.initiateUpload.json HTTP/1.1] com.adobe.cq.assetcompute.impl.servlet.InitiateUploadAssetServlet initiate upload complete asset : Mountain Biking the Uetliberg in Zurich.mp4, size: 74013446, mimeType: video/mp4

I know that this involves lot of steps for the first time, but believe me going forward it is much easy then downloading the entire log file form cloud manager instance. You just need to authenticate using browser based authentication and then run the command directly.

Note:- In order to speed up the tailing make note of your last command for example in my case $ aio cloudmanager:tail-log 1126502 author aemerror , so that you can run it directly going forward.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.