Logging¶
nib.logger is the SDK logger. App code can use it. Output goes to stdout and to the log file shared with the Swift runtime, in the runtime's line format.
Usage¶
import nib
nib.logger.info("Connected", host="example.com")
nib.logger.warn("Asset not found", path="icon.png")
try:
refresh()
except Exception as e:
nib.logger.error("Refresh failed", exc=e)
Keyword arguments are appended as key=value. error(exc=e) appends the exception type and message and logs the traceback.
Methods¶
| Method | Description |
|---|---|
debug(message, **context) |
Detailed diagnostics. Hidden unless the level is DEBUG. |
info(message, **context) |
General information. The default level. |
warn(message, **context) |
Something recoverable went wrong. |
error(message, exc=None, **context) |
A failure, optionally with the exception and its traceback. |
success(message, **context) |
Logged at INFO, shown green on the console. |
progress(current, total, message="") |
Inline progress bar on the console. |
set_level(level) |
Minimum LogLevel to emit. |
set_file(path) |
Log file path. None disables file output. |
set_colors(enabled) |
ANSI colours on the console. |
LogLevel¶
nib.LogLevel is an IntEnum: DEBUG, INFO, WARN, ERROR.
nib.logger.set_level(nib.LogLevel.DEBUG)
Environment¶
Read once, on first use.
| Variable | Default | Effect |
|---|---|---|
NIB_LOG_LEVEL |
info |
debug, info, warn or error. |
NIB_LOG_FILE |
/tmp/nib-<identifier>.log |
Log file path, shared with the runtime. Rotated to .1 at 5 MB. |
NIB_LOG_CONSOLE |
1 |
0 silences stdout. |
NIB_LOG_FILE_ENABLED |
1 |
0 disables file output. |
NO_COLOR, NIB_NO_COLOR |
unset | Disable colours. Colours are also off when stdout is not a terminal. |
Related¶
- Architecture: log file location
- nib run:
-vand-vv