Support Ukraine 🇺🇦 Help Provide Humanitarian Aid to Ukraine.
For Developers

Stream logs to CLI with apex:log:tail

3 min read
Laptop

 

Salesforce DX is a new set of tools that streamlines the entire development life cycle. It improves team development and collaboration, facilitates automated testing and continuous integration, and makes the release cycle more efficient and agile.

A recent addition to the set Salesforce DX commands is apex:log:tail. The command works against any org you have connected to the DX CLI, including production and sandbox orgs. However, if you run it from the same folder as a DX project it will use the currently configured default user/scratch org for that project.

As a developer, we extensively rely on debug logs for analysing our code for bugs, platform limits usage, etc. Most of the times, we have been using Developer Console logs pane. On first look at the output from this command, you will get a feeling as if the Developer Console logs pane has moved into your CLI console 🙂

And, it actually has moved into your CLI console with additional features. Here are list of options available with this command

Usage: sfdx force:apex:log:tail image: /uploads/ image: /uploads/ image: /uploads/ image: /uploads/ image: /uploads/ image: /uploads/

start debug logging and display logs

Flags:

-c, –color                          colorize noteworthy log lines

-d, –debuglevel DEBUGLEVEL          debug level for trace flag

-s, –skiptraceflag                  skip trace flag setup

-u, –targetusername TARGETUSERNAME  username or alias for the target org;

overrides default target org

–json                               format output as json

–loglevel LOGLEVEL                  logging level for this command invocation

(error*,trace,debug,info,warn,fatal)

You can add colors to your debug logs!

The –color parameter enables some basic color highlighting for method, constructor, variable assignments etc.

You can also customize your own colors by setting the SFDX_APEX_LOG_COLOR_MAP environment variable to an absolute file path to a JSON file per the format shown below.

{    CONSTRUCTOR_: ‘magenta’,    EXCEPTION_: ‘red’,    FATAL_: ‘red’,    METHOD_: ‘blue’,    SOQL_: ‘yellow’,    USER_: ‘green’,    VARIABLE_: ‘cyan’ }

Pipe the output!

Last but not the least, we can pipe the output from this command to filter out only what we are looking for using grep utility command as shown below.

apex:log:tail command is definitely going to help developers access debug logs faster and make their life easier with some useful parameters.

Happy coding!


About CloudAnswers

Salesforce apps, powerful components, custom development, and consulting. Our experienced team helps you to create and modify workflow processes in salesforce.

Related Articles

For Administrators

5 Hottest Updates in Salesforce Summer ’24 for Admins

Salesforce has 3 major releases every year: Spring, Summer, and Winter. The Summer 24 release is rolling out in 3 stages: May 17th, June 7th, and June 14th, respectively. Sandboxes will be updated on May 10, but if you want to get hands-on early, you can sign up for a preview org by following the link below. Getting to the good stuff, there are some major quality-of-life updates for Admins, features like the automation app, Einstein for Flow, Field tracking history, personal labels, and improved permission set interfaces, to highlight a few.

Ian Cosgrove

3 min read

Discover more from CloudAnswers

Subscribe now to keep reading and get access to the full archive.

Continue reading