Skip to content
Discussions/App Development/How to make debug statements visible in the Canton Sandbox logsForum ↗

How to make debug statements visible in the Canton Sandbox logs

App Development4 posts255 viewsLast activity Jul 2023
WA
WallaceKellyOP
May 2023

Three years ago, to make debug statements visible in the sandbox logs, @cocreature suggested the following:

…write a custom logback configuration file
You can find the default logback config used by daml sandbox at
$HOME/.daml/sdk/$YOUR_SDK_VERSION/daml-sdk/sandbox-logback.xml .

Today’s Canton-based Daml SDK does not have a sandbox-logback.xml file.

Two questions:

  1. Where can I find the equivalent in the Daml SDK 2.6? Is this logback.xml the one I’m looking for?

  2. What do I need to add to the logback file to include the output of debug statements in the log file?

RA
Ratko_Veprek
May 2023

The daml sandbox command is a very thin wrapper around the canton application. If you need to debug, I’d recommend to run canton directly:

https://docs.daml.com/canton/tutorials/getting_started.html

For debugging, you might find these two guides helpful:

https://docs.daml.com/canton/usermanual/monitoring.html#logging

https://docs.daml.com/canton/usermanual/troubleshooting_guide.html

WA
WallaceKelly
May 2023

For large models and in-depth debugging, I’m sure you are right, @Ratko_Veprek – run canton directly.

I was still curious, for the use case of simple tutorials and demos, how to get visibility to debug output when using daml start and Navigator. I learned more about Logback than I wanted. Here is what I found works:

  1. Copy the Canton logback.xml file into your project root.
    jar xf ~/.daml/sdk/<SDK VERSION>/canton/canton.jar logback.xml

  2. Add the following to the logback.xml before the closing </configuration>:

     <if condition='isDefined("LOG_DAML_TRACELOG")'>
       <appender name="TRACELOG_FILE" class="ch.qos.logback.core.FileAppender">
         <file>log/trace.log</file>
         <encoder>
           <pattern>%date [%thread] %-5level %logger{10} &entityCorrelationIdTrailingSpaceReplace;</pattern>
         </encoder>
       </appender>
       <logger name="daml.tracelog" level="DEBUG">
         <appender-ref ref="TRACELOG_FILE" />
       </logger>
     </if>
    
  3. export _JAVA_OPTIONS="-Dlogback.configurationFile=./logback.xml"

  4. LOG_DAML_TRACELOG=1 daml start

I now see the output of my debug statements in a log/trace.log file.

If this looks good to others, we could add it to the default logback.xml file.

Actually, I get duplicate entries in my log/trace.log file. As best I can tell, that is not related to my logback.xml edits. So I’ll leave that for another question.

DA
David_Martins
Jul 2023

To further extend on this topic, is it possible to define a new logback file in ledger run time? Or any way to change log level while ledger is still running?

← Back to Discussions