slog/tests/slog.c

49 lines
959 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-30T16:54:25.251770492-06:00 level=INFO source=tests/slog.c:36 func=main msg=hello ok=true
SLOG_ERROR(&l2, "hello");
// stderr:
// time=2025-09-30T16:54:25.251826602-06:00 level=ERROR msg=hello
l1.Handler(&l1, SlogLevelWarn + 1, "my message", NULL, 0, NULL);
// stdout:
// time=2025-09-30T16:54:25.251831572-06:00 level=WARN+1 msg=my message
return 0;
}