For Developers

Stream logs to CLI with apex:log:tail

2 min read
CloudAnswers photo
CloudAnswers
Share
TODO

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 :)

first.png

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.

second.png

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.

third.png

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!


CloudAnswers photo
CloudAnswers
Share

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 Developers

Batch Apex Error Event - CloudAnswers Hackathon

A hackathon is an event usually put together by a tech organization. The event brings programmers together over a specific period to collaborate on a project.

June 28, 2021

5 Min Read

For Developers

Save DOM Element As Image Attachment In Salesforce

Use a dom-to-image Javascript library that can turn arbitrary DOM nodes into a vector (SVG) or raster (PNG or JPEG) image in Salesforce.

April 8, 2021

3 Min Read

For Developers

Embed Image In Conga Document Using Salesforce ID

Learn how you can embed an image uploaded as a Salesforce Attachment in a Conga Document. Use the Conga IMAGE tag you can embed images.

February 25, 2021

4 Min Read