diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2017-02-13 16:28:28 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-02-15 09:29:39 +1000 |
commit | 92196ce55556153e87a0cf0c9d69782d3643b964 (patch) | |
tree | ecd56e9f991088d744b371ab743dcd94db0f4a55 /tools | |
parent | 63fcf46951118b94a37070cfe48f16ac9690457f (diff) |
tools: print errors as red, info as highlighted
makes it easier to filter out debugging messages
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/shared.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/shared.c b/tools/shared.c index 1019184..81608c0 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -72,7 +72,25 @@ log_handler(struct libinput *li, const char *format, va_list args) { +#define ANSI_HIGHLIGHT "\x1B[0;1;39m" +#define ANSI_RED "\x1B[0;31m" +#define ANSI_NORMAL "\x1B[0m" + static int is_tty = -1; + + if (is_tty == -1) + is_tty = isatty(STDOUT_FILENO); + + if (is_tty) { + if (priority >= LIBINPUT_LOG_PRIORITY_ERROR) + printf(ANSI_RED); + else if (priority >= LIBINPUT_LOG_PRIORITY_INFO) + printf(ANSI_HIGHLIGHT); + } + vprintf(format, args); + + if (is_tty && priority >= LIBINPUT_LOG_PRIORITY_INFO) + printf(ANSI_NORMAL); } void |