test
This commit is contained in:
parent
f8f6b28152
commit
7430bc62ff
3 changed files with 46 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
17
README.md
17
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 <slog/slog.h>
|
||||
#include <stdbool.h>
|
||||
|
|
|
|||
20
tests/minimal.c
Normal file
20
tests/minimal.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <slog/slog.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in a new issue