Logging
Both CLIs (BookAtlas.Exporter and BookAtlas.Generator) log through the same small helper,
Diagnostics/Logger.cs. Each project has its own copy because the generator can’t reference the
exporter (see Architecture). Keep the two copies identical apart from their
namespace and doc comment.
Two streams
| Stream | Carries | Examples |
|---|---|---|
| stdout | The command’s own output, written with Console.Write* | archive listings, --stats, histograms, decoded VMAD blocks |
| stderr | The log, written with Log.* | progress, summaries, warnings, errors |
You can redirect a command’s output to a file (> out.txt) and still see the log in the terminal,
or silence the log with 2>/dev/null.
Status line
A long stage of the exporter can show its progress on a status line under the log: the worldspace
map commands do, see Output and logging.
Diagnostics/StatusLine.cs wraps stderr, and the logger writes through it:
- the status line is rewritten in place (a carriage return, the text, then an erase to the end of the line), cut to the terminal’s width so it never wraps;
- a log line erases it, is written, then the status line is drawn again under it, so a warning or a
--verboseline never mixes with the progress; - the stage erases it when it ends, even on a failure.
When stderr is not a terminal (a file, a pipe), the status line is off: no carriage return, no escape sequence, only the log lines. A stage that shows a status line logs its progress some other way for that case, the map commands at each tenth of a large map. The generator has no status line.
Levels
| Level | Prefix | Shown | Use it for |
|---|---|---|---|
Log.Debug | [DEBUG] | with --verbose / -v | per-file and per-record detail, known gaps, full lists behind a counted warning |
Log.Info | [INFO] | always | one line per stage or per language: what was read, what was written, where |
Log.Warn | [WARN] | always | an incoherent or unexpected state the run recovers from |
Log.Error | [ERROR] | always | the command can’t do its job, or part of the output is missing |
A continuation line of a multi-line message is indented under the message text.
Warning or debug?
A warning means “the data isn’t what it should be”: a missing plugin or archive, a FormId whose master index isn’t in the master table, a string id missing from its string table, a texture referenced but not shipped, a malformed subrecord that was skipped. Someone should look at it.
A known limitation of this codebase is not a warning. An unsupported Havok shape type or a font face the fontconfig maps to a font no library embeds is expected, documented behavior: log it at debug level and, when useful, log one info line with the count.
When one cause can produce many warnings, log one warning with the count and the full list at
debug level (see Datasets/Merging/UnresolvedFormIdReport.cs and the generator’s unresolved image
report). The warning says “Run with –verbose to list them.”
Exit code and summary
Program.cs builds the logger from --verbose and passes the command’s exit code through
Logger.Complete. It logs Finished with N warning(s) and M error(s). when either count is
non-zero, and turns any logged error into exit code 1. A command reports failure with
Log.Error(...) and a return; it doesn’t need its own exit code.
Where logging happens
CreationEngineFormatsnever logs. It throwsInvalidDataExceptionfor malformed input or returns the problem as data.- Pure transforms in the CLIs (mergers, a dataset’s
MergeandBuildAsync, resolvers) return what they dropped or couldn’t resolve (for exampleBookMergeResult.UnresolvedFormIds,LocationMergeResult.UnresolvedFormIds,BookLocalizationResolver.CountUnresolved). The dataset’sReportlogs what a merge dropped, once per session; the pipeline logs the rest. This keeps them testable without capturing console output. - Code that does I/O against game files (
Game/Assets/, the font export, the interior resolvers) may log directly, with enough context to find the source: plugin, language, FormId, archive path. - Don’t log inside a per-record hot loop, even at debug level. Aggregate, then log once. Guard a
debug message that is costly to build with
Log.IsDebugEnabled.