Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created September 16, 2015 00:56
Show Gist options
  • Save warmwaffles/6205903ae5b75a062e55 to your computer and use it in GitHub Desktop.
Save warmwaffles/6205903ae5b75a062e55 to your computer and use it in GitHub Desktop.
#ifndef UTILS_LOGGING_H
#define UTILS_LOGGING_H
#include <stdio.h>
/**
* Default logging level will be INFO
*/
#ifndef LOGLEVEL
#define LOGLEVEL 4
#endif
#if LOGLEVEL > 5
#define log_trace(M, ...) fprintf(stderr, "[TRACE] " M " at %s (%s:%d)\n", ##__VA_ARGS__, __func__, __FILE__, __LINE__)
#else
#define log_trace(M, ...)
#endif
#if LOGLEVEL > 4
#define log_debug(M, ...) fprintf(stderr, "[DEBUG] " M " at %s (%s:%d)\n", ##__VA_ARGS__, __func__, __FILE__, __LINE__)
#else
#define log_debug(M, ...)
#endif
#if LOGLEVEL > 3
#define log_info(M, ...) fprintf(stderr, "[INFO] " M " at %s (%s:%d)\n", ##__VA_ARGS__, __func__, __FILE__, __LINE__)
#else
#define log_info(M, ...)
#endif
#if LOGLEVEL > 2
#define log_warn(M, ...) fprintf(stderr, "[WARN] " M " at %s (%s:%d)\n", ##__VA_ARGS__, __func__, __FILE__, __LINE__)
#else
#define log_warn(M, ...)
#endif
#if LOGLEVEL > 1
#define log_error(M, ...) fprintf(stderr, "[ERROR] " M " at %s (%s:%d)\n", ##__VA_ARGS__, __func__, __FILE__, __LINE__)
#else
#define log_error(M, ...)
#endif
#if LOGLEVEL > 0
#define log_fatal(M, ...) fprintf(stderr, "[FATAL] " M "\n",)
#else
#define log_fatal(M, ...)
#endif
#endif // UTILS_LOGGING_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment