common: enhancement++ of the logging method

Logging tags are marked with the corresponding
log type color, the file and the line information
in gray, and the message content in the default
color.

@Issue: https://github.com/thorvg/thorvg/issues/1351
This commit is contained in:
Mira Grudzinska 2023-04-12 16:51:55 +02:00 committed by Hermet Park
parent 7bb6713505
commit 0a3718f923

View file

@ -67,9 +67,10 @@ enum class FileType { Tvg = 0, Svg, Raw, Png, Jpg, Unknown };
#ifdef THORVG_LOG_ENABLED #ifdef THORVG_LOG_ENABLED
constexpr auto ErrorColor = "\033[31m"; //red constexpr auto ErrorColor = "\033[31m"; //red
constexpr auto LogColor = "\033[32m"; //green constexpr auto LogColor = "\033[32m"; //green
constexpr auto GreyColor = "\033[90m"; //grey
constexpr auto ResetColor = "\033[0m"; //default constexpr auto ResetColor = "\033[0m"; //default
#define TVGERR(tag, fmt, ...) fprintf(stderr, "%s" tag " (%s l.%d): " fmt "%s\n", ErrorColor, __FILE__, __LINE__, ##__VA_ARGS__, ResetColor) #define TVGERR(tag, fmt, ...) fprintf(stderr, "%s" tag "%s (%s l.%d): %s" fmt "\n", ErrorColor, GreyColor, __FILE__, __LINE__, ResetColor, ##__VA_ARGS__)
#define TVGLOG(tag, fmt, ...) fprintf(stderr, "%s" tag " (%s l.%d): " fmt "%s\n", LogColor, __FILE__, __LINE__, ##__VA_ARGS__, ResetColor) #define TVGLOG(tag, fmt, ...) fprintf(stderr, "%s" tag "%s (%s l.%d): %s" fmt "\n", LogColor, GreyColor, __FILE__, __LINE__, ResetColor, ##__VA_ARGS__)
#else #else
#define TVGERR(...) #define TVGERR(...)
#define TVGLOG(...) #define TVGLOG(...)