# Write to logfile

I want to write some things to the log file. What is the best practice for this? Is it `\message{}` or `\typeout{}` or what?

-

The Plain TeX command `\wlog` is available also in LaTeX

``````\wlog{This will be written in the log file}
``````

The macro `\wlog` expands to `\immediate\write-1`, and by rule the argument will be written out only in the log file and won't appear in the terminal.

When `\write` is followed by a number between 0 and 15 (included), the write operation is made on the output stream with that number if open at the time the write is performed (immediately or when the output routine is in action, according whether `\immediate` precedes `\write` or not). If the output stream is not open or the number is non negative, the argument to `\write` is written on the terminal and in the log file. Conversely, when the number is negative the argument is written only in the log file.

Exception: in most TeX distribution, `\write18` passes the argument to the operating system, provided shell escape is enabled (possibly in restricted mode, see the manual of TeX Live or MiKTeX).

The LaTeX command `\typeout` does `\immediate\write\@unused`, so it writes the argument both to the terminal and to the log file. There is no predefined command of this kind in Plain TeX. Indeed `\typeout` also gives `\protect` a suitable meaning for coping with fragile commands in the argument. The `\@unused` stream is permanently unassigned to a file.

Also `\message` writes both in the terminal and the log file, but it doesn't force a new line, which instead is done by `\write` when the output is directed to the log file.

-
Is there a Plain TeX command to write in the log file and in the terminal? –  Paul Gaborit Aug 30 '12 at 17:19
What's the difference between `\wlog`, `\typeout`, and `\message`? –  lpdbw Aug 30 '12 at 19:09