Created
May 10, 2014 21:41
-
-
Save Informatic/62aaa3ae900de07a238d to your computer and use it in GitHub Desktop.
Simple but cute GCC logging facilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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