Support Ukraine ūüáļūüᶠHelp Provide Humanitarian Aid to Ukraine.
For Developers

Stream logs to CLI with apex:log:tail

2 min read
CloudAnswers photo

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


-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


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!

CloudAnswers photo

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

Tips for Becoming a Salesforce Developer

Interested in becoming a Salesforce developer? In this blog post Jagmohan has put together his favorite tips and resources to get started in the world of Salesforce development.

April 4, 2024

6 Min Read

For Developers

Designing User Security and Visibility in Salesforce

Trust and security are at the top of Salesforce's priority list. The platform has everything you need if you're looking to construct a robust user security paradigm. However, this security approach has flaws that an attacker can exploit to gain access to your data. The Salesforce Architect has the duty to ensure that these features are set up correctly.

March 16, 2022

7 Min Read

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