Cozy Log Writer is a basic logging module for Nim programs. It automatically uses a styled or plain text format depending on whether the output file is a terminal or not. The module also reads and respects the NO_COLOR
environment variable by default.
- Supports different log levels: log, info, warn, err, panic
- Styled output with colours and UTF icons for terminal output
- Plain text output for non-terminal output
- Respects the
NO_COLOR
environment variable (unless compiled with-d:ClwIgnoreNocolor
)
Cozy Log Writer is not yet the nimble directory, git clone
or just download the module.
Upon acceptance in the nimble directory, use atlas
or nimble
to install:
atlas use cozytaskpool
nimble install cozytaskpool
import pkg/cozylogwriter
# Initialize the logger with stderr as the output file
newCozyLogWriter(stderr)
log("This is a log message", (complex: "types", are: "stringified", n: 42))
info("This is an info message")
warn("This is a warning message")
err("This is an error message")
panic("This is a panic message") # Exits the program with code 1
panicWithCode(QuitSuccess, "This is a panic message") # Exits the program with a given code
Warning
The logger uses a global object internally and is not thread-safe. The module does not prevent or manage concurrent access in any way.
Documentation is included. You can generate it locally with nim doc cozylogwriter.nim
.
Cozy Log Writer is licensed under GNU General Public License version 2.0 or later. See the LICENSE file for details.