summaryrefslogtreecommitdiff
path: root/examples/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/logging.c')
-rw-r--r--examples/logging.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/logging.c b/examples/logging.c
new file mode 100644
index 0000000..1d2744c
--- /dev/null
+++ b/examples/logging.c
@@ -0,0 +1,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;
+}