Skip to content

Instantly share code, notes, and snippets.

@Informatic
Created May 10, 2014 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Informatic/62aaa3ae900de07a238d to your computer and use it in GitHub Desktop.
Save Informatic/62aaa3ae900de07a238d to your computer and use it in GitHub Desktop.
Simple but cute GCC logging facilities
#include <stdio.h>
#ifndef VERBOSITY_LEVEL
#define VERBOSITY_LEVEL 3
#endif
#define _stringify2(n) #n
#define _stringify(n) _stringify2(n)
#define PRINT_MESSAGE(type, color, fmt, ...) printf("\033[0;" color "m" \
__FILE__ "@" _stringify(__LINE__) " \033[1;" color "m" type ":\033[0;" \
color "m " fmt "\033[0m\n", ##__VA_ARGS__)
#if VERBOSITY_LEVEL >= 0
#define E(...) PRINT_MESSAGE("ERROR", "31", __VA_ARGS__)
#else
#define E(...)
#endif
#if VERBOSITY_LEVEL >= 1
#define W(...) PRINT_MESSAGE("WARN", "33", __VA_ARGS__)
#else
#define W(...)
#endif
#if VERBOSITY_LEVEL >= 2
#define I(...) PRINT_MESSAGE("INFO", "36", __VA_ARGS__)
#else
#define I(...)
#endif
#if VERBOSITY_LEVEL >= 3
#define D(...) PRINT_MESSAGE("DEBUG", "35", __VA_ARGS__)
#else
#define D(...)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment