slog/tests/slog.c
2025-09-30 09:42:31 -06:00

45 lines
806 B
C

#include <slog/slog.h>
#include <stdbool.h>
int main(void)
{
struct SlogHandlerOpts opts1 = {
.File = stdout,
.MinLevel = SlogLevelDebug,
.Prefix = NULL,
.AddSource = true,
.Json = false,
};
struct SlogLogger l1 = {
SlogTextHandler,
opts1,
};
struct SlogHandlerOpts opts2 = {
.File = stderr,
.MinLevel = SlogLevelError,
.Prefix = "scope",
.AddSource = false,
.Json = true,
};
struct SlogLogger l2 = {
SlogTextHandler,
opts2,
};
struct SlogAttr attrs[] = {
SlogAttrB("ok", true),
};
SLOG_INFO_ATTRS(&l1, "hello", attrs);
// stdout:
// time=2025-09-30T09:38:32.607139416-06:00 level=INFO msg=hello source=tests/slog.c:36 func=main ok=true
SLOG_ERROR(&l2, "hello");
// stderr:
// time=2025-09-30T09:38:32.607139416-06:00 level=INFO msg=hello
return 0;
}