Skip to content

Instantly share code, notes, and snippets.

@abstractOwl
Last active August 29, 2015 14:01
Show Gist options
  • Save abstractOwl/e512ce07925e5e38b08e to your computer and use it in GitHub Desktop.
Save abstractOwl/e512ce07925e5e38b08e to your computer and use it in GitHub Desktop.
Simple C Logging Library
#include <stdio.h>
#define LOG_NONE (0)
#define LOG_WARN (1)
#define LOG_INFO (2)
#define WARN(...)
#define INFO(...)
#define LOG_LEVEL LOG_INFO // Set log level here
#define LOG(msg, args...) \
do { \
printf("[%s] (%s:%d) " msg "\n", __func__, __FILE__, __LINE__, ##args); \
} while (0)
#if LOG_LEVEL >= LOG_WARN
#undef WARN
#define WARN(msg, args...) LOG("WARN - " msg, ##args)
#endif
#if LOG_LEVEL >= LOG_INFO
#undef INFO
#define INFO(msg, args...) LOG("INFO - " msg, ##args)
#endif
#include <stdio.h>
#define DEBUG
#ifdef DEBUG
#define LOG(...) printf(__VA_ARGS__);
#endif
#include <stdio.h>
#define LOG_NONE (0)
#define LOG_WARN (1)
#define LOG_INFO (2)
#define WARN(...)
#define INFO(...)
#define LOG_LEVEL LOG_WARN // Set log level here
#if LOG_LEVEL >= LOG_WARN
#undef WARN
#define WARN(msg, args...) printf("[WARN] " msg, ##args)
#endif
#if LOG_LEVEL >= LOG_INFO
#undef INFO
#define INFO(msg, args...) printf("[INFO] " msg, ##args)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment