---
url: /dyad/stable/tutorials/debug-logging.md
description: >-
  Tracing the synchronous-program compiler when a clocked Dyad model fails to
  compile.
---

# Debug Logging {#debug-logging}

When a clocked model fails during compilation, the error is often generic — it says that something went wrong inside code generation without saying what. This page covers how to enable diagnostic output from the compiler.

This is diagnostic output about the *compiler*. For recording what a program computed at run time, see [Logging data from inside the program](/tutorials/discrete-external-functions#discrete-external-functions); for the solver's own output during a simulation, `TransientAnalysis` takes a `log_file` argument (see [`TransientAnalysis`](../analyses/transient.md)).

## Enabling debug output {#Enabling-debug-output}

`SynchToolkit` writes its intermediate results to a debug channel, off by default:

```julia
using SynchToolkit

SynchToolkit.enable_debug!(:sj)     # one stage
SynchToolkit.enable_debug!()        # every stage
SynchToolkit.disable_debug!()       # disable debug output
```

The stages are:

|          Group |                                                                   Shows |
| --------------:| -----------------------------------------------------------------------:|
|          `:sj` |           The synchronous-program node and the generated module source. |
|     `:codegen` |                                       The code-generation stage itself. |
|     `:compile` |                                                 The compilation result. |
| `:integration` | How the clocked partitions are attached to the continuous-time problem. |
|        `:init` |                                                Initialization handling. |

Enable `:sj` first: it prints the generated module, which is the relevant output when a model fails with an internal code-generation error rather than a modeling error.

## Reading a code-generation failure {#Reading-a-code-generation-failure}

A failure inside code generation is logged with an error message such as

```
Failed to evaluate the generated runtime module ##SynchRuntime#281. This is a bug in
SynchToolkit's code generation; use `SynchToolkit.enable_debug!(:sj)` to inspect the
generated code.
```

after which the exception that evaluating the module threw is rethrown, so the stack trace shows the original error. Enabling `:sj` then prints the module that failed to evaluate, and the fault is usually visible in it — a name that does not resolve, a type that is not concrete, an operator that was not translated.

## What to do with the result {#What-to-do-with-the-result}

A code-generation failure is generally not something to work around in the model. If the generated module is malformed, report it with the model that produced it — the generated source and the exception together are usually sufficient to localise the problem.

Errors caused by the model have a different form: they name a variable, a clock or an equation, and they come from clock inference rather than code generation. Those are covered by the [clock-error troubleshooting table](/tutorials/discrete-time-modeling#discrete-time-troubleshooting).

## See also {#See-also}

* [Julia Functions, Side Effects and Hardware](/tutorials/discrete-external-functions#discrete-external-functions) — logging data from inside a program

* [Discrete-Time Modeling](/tutorials/discrete-time-modeling#discrete-time-modeling) — clocks, and clock errors that are modeling errors
