Newer Version Available

This content describes an older version of this product. View Latest

Log Messages and Log Levels

Salesforce CLI writes all log messages to the USER_HOME_DIR/.sf/sf.log file. CLI invocations append log messages to this running log file. Only errors are output to the terminal or command window from which you run the CLI.

The files in the USER_HOME_DIR/.sf directory are used internally by Salesforce CLI. Don’t remove or edit them.

Important

The default level of log messages is warn. You can set the log level to one of the following, listed in order of least to most information. The level is cumulative: for the debug level. The --loglevel parameter supports parameter values in only lowercase (due to the migration to oclif). To assist you with the transition, we support uppercase parameters in Spring ’19 but plan to deprecate support for them in Summer ’19.

  • error
  • warn
  • info
  • debug
  • trace
  • fatal

You can change the log level in two ways, depending on what you want to accomplish.

To change the log level for the execution of a single CLI command, use the --loglevel parameter. Changing the log level in this way doesn’t affect subsequent CLI use. This example specifies debug-level log messages when you create a scratch org.

1sfdx force:org:create --definitionfile config/project-scratch-def.json --loglevel debug --setalias my-scratch-org

To globally set the log level for all CLI commands, set the SFDX_LOG_LEVEL environment variable. For example, on UNIX:

1export SFDX_LOG_LEVEL=debug

Salesforce CLI gathers diagnostic information about its use and reports it to Salesforce so that the development team can investigate issues. The type of information includes command duration and command invocation counts.

Note

Rotating Log Files

Salesforce CLI uses rotating log files. By default, every day at midnight the CLI makes a backup copy of the log file and then clears out its entries to start afresh. We keep backups for the past two days along with the current day’s logs. This behavior ensures that the current log file doesn't get too large.

You can change the default behavior with these environment variables:
  • SFDX_LOG_ROTATION_PERIOD: How often a new log file is created, such as the default value of one day (1d) or two weeks 2w.
  • SFDX_LOG_ROTATION_COUNT: Number of backup files to keep. Default value is 2.

For example, let's say you choose a rotation period of 2 weeks and a count of 2. These values ensure that you have backup logs for the four weeks before the first entry in the current log.