diff --git a/CMakeLists.txt b/CMakeLists.txt index fbd73ae..1eac4e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,17 +12,15 @@ else() add_compile_options(-Wall -Wextra -Wpedantic) endif() + enable_testing() -add_executable(slog_tests - tests/slog.c -) +add_executable(slog_main tests/slog.c) +target_compile_options(slog_main PRIVATE -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=) +target_include_directories(slog_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME slog_main COMMAND slog_main) -target_compile_options(slog_tests - PRIVATE - -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/= -) - -target_include_directories(slog_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - -add_test(NAME slog_tests COMMAND slog_tests) +add_executable(slog_minimal tests/minimal.c) +target_compile_options(slog_minimal PRIVATE -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=) +target_include_directories(slog_minimal PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME slog_minimal COMMAND slog_minimal) diff --git a/README.md b/README.md index a493373..414843b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,23 @@ Single-header structured logger in C99 +# Simple usage + +```c + ... + struct SlogLogger logger = SLOG_DEFAULT_TEXT_LOGGER; + + struct SlogAttr attrs[] = { + SlogAttrB("ok", true), + }; + + SLOG_INFO(&logger, "hello", attrs); // or: SLOG_DEBUG, SLOG_WARN, SLOG_ERROR + // time=2025-09-29T17:46:49.409721457-06:00 level=INFO msg=hello ok=true + ... +``` + +# Advanced usage + ```c #include #include diff --git a/tests/minimal.c b/tests/minimal.c new file mode 100644 index 0000000..21e8358 --- /dev/null +++ b/tests/minimal.c @@ -0,0 +1,20 @@ +#include +#include + +int main(void) +{ + struct SlogLogger logger = SLOG_DEFAULT_TEXT_LOGGER; + + struct SlogAttr attrs[] = { + SlogAttrB("ok", true), + }; + + SLOG_INFO(&logger, "hello", attrs); + // time=2025-09-29T17:46:49.409721457-06:00 level=INFO msg=hello ok=true + + // SLOG_INFO(&logger, "hello", NULL); + // Warning: size of pointer is divided by size of pointed type + // but still could be used. + + return 0; +}