Simple logging library with a unified interface to os_log, syslog, Logcat, and TraceLogging.
#include <log.h>
log_open("some-log", 0);
log_debug("Current pid: %u", getpid());
log_close();
On macOS, Console.app and the log
tool can be used to consume logs. To show only message for a given log, such as some-log
in the previous example, pass the --predicate
flag:
log stream --predicate "subsystem == '<name>'"
On Linux, journalctl
can be used to consume logs. To show only messages for a given log, such as some-log
in the previous example, pass the --identifier
flag:
journalctl --identifier <name>
On Android, logcat
can be used to consume logs. To show only messages for a given log, such as some-log
in the previous example, pass a filterspec:
adb logcat "*:S some-log:*"
This will silence all logs by default (*:S
) and show only those with a name of some-log
for all priorities (:*
).
On Windows, the tracelog
and traceview
tools from the Windows SDK can be used to consume logs. To start a trace on the command line using tracelog
for a given log, such as some-log
in the previous example, do:
tracelog -start my-trace -guid *some-log -f log.etl
When done collecting logs, stop the trace:
tracelog -stop my-trace
To summarize and view the collected logs, use tracefmt
:
tracefmt log.etl -o log.txt
See include/log.h
for the public API.
Apache 2.0