common: enhancement of the logging method

Introducing colors for various log types.
For error messages, the file name and line
number are now included.

@Issue: https://github.com/thorvg/thorvg/issues/1351
This commit is contained in:
Mira Grudzinska 2023-04-11 01:11:15 +02:00 committed by Hermet Park
parent b866ee9cac
commit 54cfd45165

View file

@ -65,8 +65,11 @@ using namespace tvg;
enum class FileType { Tvg = 0, Svg, Raw, Png, Jpg, Unknown };
#ifdef THORVG_LOG_ENABLED
#define TVGLOG(tag, fmt, ...) fprintf(stdout, tag ": " fmt "\n", ##__VA_ARGS__) //Log Message for notifying user some useful info
#define TVGERR(tag, fmt, ...) fprintf(stderr, tag ": " fmt "\n", ##__VA_ARGS__) //Error Message for us to fix it
constexpr auto ErrorColor = "\033[31m"; //red
constexpr auto LogColor = "\033[32m"; //green
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 TVGLOG(tag, fmt, ...) fprintf(stderr, "%s" tag " (%s l.%d): " fmt "%s\n", LogColor, __FILE__, __LINE__, ##__VA_ARGS__, ResetColor)
#else
#define TVGERR(...)
#define TVGLOG(...)