Bladeren bron

Add color to logs

master
Ben Kurtovic 8 jaren geleden
bovenliggende
commit
1a00100fe6
1 gewijzigde bestanden met toevoegingen van 11 en 8 verwijderingen
  1. +11
    -8
      src/logging.h

+ 11
- 8
src/logging.h Bestand weergeven

@@ -26,19 +26,22 @@
#define PRINT_ERR_ fprintf(stderr, ": %s", strerror(errno))
#define EXIT_FAIL_ exit(EXIT_FAILURE)

#define DEBUG_TEXT_ "\x1b[0m\x1b[37m[DEBUG]\x1b[0m"
#define TRACE_TEXT_ "\x1b[1m\x1b[33m[TRACE]\x1b[0m"
#define FATAL_TEXT_ "\x1b[1m\x1b[31m" "fatal:" "\x1b[0m"
#define ERROR_TEXT_ "\x1b[1m\x1b[31m" "error:" "\x1b[0m"
#define WARN_TEXT_ "\x1b[1m\x1b[33m" "warning:" "\x1b[0m"
#define DEBUG_TEXT_ "\x1b[0m\x1b[37m" "[DEBUG]" "\x1b[0m"
#define TRACE_TEXT_ "\x1b[1m\x1b[30m" "[TRACE]" "\x1b[0m"

unsigned logging_level_;

/* Public logging macros */

#define FATAL(...) LOG_ERR_(0, "fatal:", {}, EXIT_FAIL_, __VA_ARGS__)
#define FATAL_ERRNO(...) LOG_ERR_(0, "fatal:", PRINT_ERR_, EXIT_FAIL_, __VA_ARGS__)
#define ERROR(...) LOG_ERR_(0, "error:", {}, {}, __VA_ARGS__)
#define ERROR_ERRNO(...) LOG_ERR_(0, "error:", PRINT_ERR_, {}, __VA_ARGS__)
#define WARN(...) LOG_ERR_(0, "warning:", {}, {}, __VA_ARGS__)
#define WARN_ERRNO(...) LOG_ERR_(0, "warning:", PRINT_ERR_, {}, __VA_ARGS__)
#define FATAL(...) LOG_ERR_(0, FATAL_TEXT_, {}, EXIT_FAIL_, __VA_ARGS__)
#define FATAL_ERRNO(...) LOG_ERR_(0, FATAL_TEXT_, PRINT_ERR_, EXIT_FAIL_, __VA_ARGS__)
#define ERROR(...) LOG_ERR_(0, ERROR_TEXT_, {}, {}, __VA_ARGS__)
#define ERROR_ERRNO(...) LOG_ERR_(0, ERROR_TEXT_, PRINT_ERR_, {}, __VA_ARGS__)
#define WARN(...) LOG_ERR_(0, WARN_TEXT_, {}, {}, __VA_ARGS__)
#define WARN_ERRNO(...) LOG_ERR_(0, WARN_TEXT_, PRINT_ERR_, {}, __VA_ARGS__)
#define DEBUG(...) LOG_OUT_(1, DEBUG_TEXT_, {}, {}, __VA_ARGS__)
#define TRACE(...) LOG_OUT_(2, TRACE_TEXT_, {}, {}, __VA_ARGS__)



Laden…
Annuleren
Opslaan