Simple C++ logging library using a branching method chaining interface inspired by the Rust crate fern.
#include <kern/kern.h>
DispatchBuilder()
// accept messages for all level
.sink(std::make_unique<StdoutSink>())
.chain(DispatchBuilder()
.level(LogLevel::Trace)
// use additional debug informations for trace messages
.format([](auto meta, auto msg, auto buf) {
snprintf(buf, BUF_SIZE, "[%s] %s:%d | %s", meta.level_str, meta.function, meta.line, msg);
})
.sink(std::make_unique<FileSink>("/var/log/foobar.trace"))
.build())
// write error and fatal messages to stdout and stderr
.chain(DispatchBuilder()
.min_level(LogLevel::Error)
.sink(std::make_unique<StderrSink>())
// additionaly write error messages into a log file
.chain(DispatchBuilder()
.sink(std::make_unique<FileSink>("/var/log/foobar.err"))
.build())
.build())
// filter all messages previously caught by a chain dispatch
.filter_chains()
.apply();
info("foo");
error("bar");
trace("baz %d %s", 6, "foobar");
- Tutorial
- Reference
kern is using parts of the catch unit-testing framework for internal testing. All necessary files are being distributed with kern and can be found in the tests/catch subdirectory. Catch is licensed under the Boost Software License 1.0