summaryrefslogtreecommitdiff
path: root/examples/logging.c
blob: 1d2744c4a2e25caee289de163127a54a6906c47a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#define NONSTD_IMPLEMENTATION
#include "../nonstd.h"

int main(void) {
    // Default level is LOG_INFO
    LOG_INFO_MSG("This is an info message: %d", 42);
    LOG_DEBUG_MSG("This debug message will NOT be shown by default");

    // Change level to LOG_DEBUG
    set_log_level(LOG_DEBUG);
    LOG_DEBUG_MSG("Now debug messages are shown: %s", "hello");

    // Warnings and Errors
    LOG_WARN_MSG("This is a warning!");
    LOG_ERROR_MSG("This is an error!");

    // Environment variable override test
    // You can set LOG_LEVEL=1 (WARN) etc.
    LogLevel env_level = get_log_level_from_env();
    if (env_level != LOG_DEBUG) {
        printf("Environment overrides level to: %d\n", env_level);
    }

    return 0;
}