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!