Enable / disable file logging without restarting the Canton process?

I recently discovered the Canton Console command logging.set_level(...). Very cool. To see it in action, do this:

docker run --rm -it --volume ./log:/canton/log \
   digitalasset/canton-open-source:2.7.6 \
   --no-tty \
   -C canton.participants.participant1.ledger-api.address=0.0.0.0 \
   -C canton.participants.participant1.ledger-api.port=5011 \
   --log-level-stdout INFO
   --log-level-canton INFO

logging.set_level("com.digitalasset.canton", "DEBUG")

exit

head log/canton.log

tail log/canton.log

You will notice that the logging level was changed. The head does not include any DEBUG messages. The tail does include DEBUG messages.

The above is convenient because you can change the logging level without requiring a restart of the process.


Question: Is there a way to similarly enable / disable logging to a file? If not, should we add support for that?


Here’s the scenario:

  • The Canton logs are being sent to a third-party log aggregator from the stdout stream. Consequently, the Canton process is started with the --log-level-stdout INFO and --log-file-appender OFF.
  • Disabling log files (i.e, --log-file-appender OFF) avoids having to allocate cloud storage for rolling log files – log files which will rarely be used.
  • If log files are needed (for example to share with DA support) the team cannot currently enable writing to the log files without changing the startup CLI options and restarting the process.
  • While the logs could be retrieved from the third-party aggregator, the log export functionality may be limited. The exported logs may not be in a consistent format. And, calling logging.set_level(...) does not currently change the stdout log-level.

Something like logging.set_log_file_appender("FLAT") would be a nice option. It would be helpful for temporarily writing DEBUG (and greater) log messages to a file without having to restart the Canton process.

Looks like the related source code is here.

1 Like

However, if you want to enable or disable logging to a file specifically, the current version of Canton does not support this functionality directly through the console commands. The logs are typically sent to a third-party log aggregator from the stdout stream, and the process is started with the --log-level-stdout INFO and --log-file-appender OFF options to avoid unnecessary file storage.