Logging¶
SIPNET's logger is a small wrapper around printf that adds standard prefixes and,
for internal errors, the source file and line number. It is defined in common/logging.h
and implemented in common/logging.c.
Levels¶
- 0: Quiet-able (suppressed by
--quiet). - 1: Always on (not suppressed).
- 2: Always on and includes
file:line.
Functions¶
logInfo: Level 0; routine progress, expected or supported behavior, configuration summaries, and transparency messages.logWarning: Level 0; conditions that may affect validity or reliability, or likely require user attention.logTest: Level 1; deterministic messages for tests/CI; not user-facing.logError: Level 1; non-recoverable problems: the run cannot continue, state is invalid, or output cannot be trusted.logInternalError: Level 2; errors that should never happen; include details and ask to report.logAppend: Level 0; continue the current log message (for example, to add more text after alogInfocall) without starting a new prefix.
Note that logAppend messages are hidden by --quiet regardless of the log level of the previous log line.
Choosing a function¶
Rule of thumb:
- Use
logErrorif the run should stop. - Use
logWarningif the user should probably stop and check the run. - Use
logInfoif the run can proceed and the message is mainly for transparency.
Usage¶
- Include the header:
#include "common/logging.h" - Log messages:
logInfo("Initialized OK\n"); logWarning("Deprecated parameter: %s\n", name); logTest("Iteration %d\n", i); logError("Missing required parameter: %s\n", key); logInternalError("Unexpected state: %d\n", code); - Example outputs:
[INFO ] Initialized OK [WARNING] Deprecated parameter: foo [TEST ] Iteration 12 [ERROR ] Missing required parameter: bar [ERROR (INTERNAL)] (myfile.c:123) Unexpected state: 5
Notes¶
- Each logging function (except
logAppend) prints a fixed prefix (e.g.,[INFO ],[WARNING],[ERROR ]). - Messages use
printf-style formatting. Include\nyourself if you want a newline. - Level 2 (
logInternalError) prints file:line; levels 0–1 print just the prefix.