Create a gist now

Instantly share code, notes, and snippets.

@abstractOwl /logc.c
Last active Aug 29, 2015

What would you like to do?
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