Skip to content

skimindex.log

skimindex.log

Logging module for skimindex — Python equivalent of __skimindex_log.sh.

Provides structured log functions with VT100 colours on terminals, automatic colour-stripping in log files, and optional OS-level stderr redirection so that all subprocess output is captured alongside skimindex messages.

Log format::

2025-03-25 14:00:00 [INFO   ] hostname.12345 -- message

Default level: INFO. Precedence: ERROR > WARNING > INFO > DEBUG.

Example
from skimindex.log import loginfo, logwarning, openlogfile, closelogfile

loginfo("Starting process")
openlogfile("/log/skimindex.log", mirror=True)
logwarning("This goes to file and screen")
closelogfile()

logdebug

logdebug(*message: str) -> None

Emit a DEBUG-level log message.

No-op when the current log level is above DEBUG. Multiple arguments are joined with a space.

Parameters:

Name Type Description Default
*message str

Message parts to log.

()

loginfo

loginfo(*message: str) -> None

Emit an INFO-level log message.

No-op when the current log level is above INFO. Multiple arguments are joined with a space.

Parameters:

Name Type Description Default
*message str

Message parts to log.

()

logwarning

logwarning(*message: str) -> None

Emit a WARNING-level log message.

No-op when the current log level is above WARNING. Multiple arguments are joined with a space.

Parameters:

Name Type Description Default
*message str

Message parts to log.

()

logerror

logerror(*message: str) -> None

Emit an ERROR-level log message.

Always emitted regardless of the current log level. Multiple arguments are joined with a space.

Parameters:

Name Type Description Default
*message str

Message parts to log.

()

setloglevel

setloglevel(level: str) -> None

Set the active log level.

Messages below the new level are silently discarded.

Parameters:

Name Type Description Default
level str

One of "DEBUG", "INFO", "WARNING", "ERROR" (case-insensitive). Unknown values are ignored with a warning.

required

openlogfile

openlogfile(
    logpath: str,
    mirror: bool = False,
    everything: bool = False,
) -> None

Open a log file and redirect subsequent log output to it.

The file is opened in append mode; parent directories are created if missing. Falls back to stderr-only logging if the path is not writable.

Parameters:

Name Type Description Default
logpath str

Path to the log file.

required
mirror bool

If True, also write each log line to stderr.

False
everything bool

If True, redirect the process's stderr file descriptor (fd 2) to the log file at the OS level, so all subprocess output is captured alongside skimindex messages.

False

closelogfile

closelogfile() -> None

Close the current log file and restore stderr output.