octolog

octolog is a logging library built on top of std/logging for multi-threaded logging, it is used channels to queue log message between different thread, then write to file or stdout.

start proc is required to initialize octolog, underneath it will spawn a single thread to listen for log message, then write it to file / stdout / stderr.

Note: you should activate thread support when using this library, include --threads:on in config.nims or build command

Basic usage

A simple example on how to use library.

import octolog, os

# start octolog
octologStart()

info "hello octolog!"
debug "hello octolog!"
warn "hello octolog!"
error "hello octolog!"
notice "hello octolog!"
fatal "hello octolog!"

# stop octolog
octologStop()

you are allow to use info("some info") or info "some info".

In this example, a log file with current datetime will be created, for example, 202404052020.log, you can initialize octologStart with different configuration.

Procs

proc disableFileLoggerLevel(levelThreshold: Level) {....raises: [], tags: [],
    forbids: [].}
proc enableFileLoggerLevel(levelThreshold: Level) {....raises: [], tags: [],
    forbids: [].}
proc octolog(level: Level; msg: string) {....raises: [ValueError, IOError],
    tags: [ReadIOEffect, TimeEffect, WriteIOEffect], forbids: [].}
Example .. code-block:: octolog(lvlInfo, "hello, there...")
proc octologStart(fileName = now().format("yyyyMMddHHmm"); useFileLogger = true;
                  fileLoggerLvl: seq[Level] = @[lvlNone];
                  useConsoleLogger = true; skipInitLog = false;
                  fileRolling = false; maxLines = 1000; bufSize = -1;
                  fmt = "[$datetime] [$levelname] $[$threadid] $appname : "): void {.
    ...raises: [IOError, OSError, ValueError, Exception],
    tags: [ReadDirEffect, ReadIOEffect, TimeEffect, WriteIOEffect, RootEffect],
    forbids: [].}

Start octolog thread with default configuration in background.

Example:

octologStart()

Start octolog thread without using file logger.

Example:

octologStart(useFileLogger=false)

Start octolog thread using rolling file logger.

Example:

octologStart(fileRolling=true)

Start octolog thread with a different log format. Default format is "[$datetime] [$levelname] [$threadid] $appname : "

Example:

octologStart(fmt="[$datetime] [$levelname]: ")

Start octolog thread with logging different log level file.

Example:

octologStart(fileLoggerLvl=@[lvlInfo, lvlDebug, lvlError])
proc octologStop(skipEndLog = false): void {....raises: [ValueError, IOError],
    tags: [ReadIOEffect, TimeEffect, WriteIOEffect], forbids: [].}
When stopping octolog thread, it will wait for all the log message clear in the channel before exit. If there are too many message inside it, it may take some time before it is really exiting it.

Templates

template debug(msg: string)
template error(msg: string)
template fatal(msg: string)
template info(msg: string)

Logging your message with template style.

Example:

info "hello, there..."
template notice(msg: string)
template warn(msg: string)