### 7.4 Saving debugging output ¶

Debug and tracing output can be redirected to files using either the `--debugfile` option to `m4` (see Invoking m4), or with the builtin macro `debugfile`:

Builtin: debugfile ([file]) ¶

  Sends all further debug and trace output to file, opened in append mode. If file is the empty string, debug and trace output are discarded. If `debugfile` is called without any arguments, debug and trace output are sent to standard error. This does not affect warnings, error messages, or `errprint` output, which are always sent to standard error. If file cannot be opened, the current debug file is unchanged, and an error is issued.

  The expansion of `debugfile` is void.

    $ m4 -d
    traceon(`divnum')
    ⇒
    divnum(`extra')
    error→m4:stdin:2: Warning: excess arguments to builtin `divnum' ignored
    error→m4trace: -1- divnum(`extra') -> `0'
    ⇒0
    debugfile()
    ⇒
    divnum(`extra')
    error→m4:stdin:4: Warning: excess arguments to builtin `divnum' ignored
    ⇒0
    debugfile
    ⇒
    divnum
    error→m4trace: -1- divnum -> `0'
    ⇒0