Merge pull request #12411 from keszybz/pr/12394

run: when emitting the calendarspec warning, use red
This commit is contained in:
Lennart Poettering
2019-05-08 10:11:32 -04:00
committed by GitHub
30 changed files with 80 additions and 26 deletions
+7 -6
View File
@@ -336,7 +336,7 @@ static int write_to_console(
char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2];
struct iovec iovec[6] = {};
bool highlight;
const char *on = NULL, *off = NULL;
size_t n = 0;
if (console_fd < 0)
@@ -347,18 +347,19 @@ static int write_to_console(
iovec[n++] = IOVEC_MAKE_STRING(prefix);
}
highlight = LOG_PRI(level) <= LOG_ERR && show_color;
if (show_color)
get_log_colors(LOG_PRI(level), &on, &off, NULL);
if (show_location) {
(void) snprintf(location, sizeof location, "(%s:%i) ", file, line);
iovec[n++] = IOVEC_MAKE_STRING(location);
}
if (highlight)
iovec[n++] = IOVEC_MAKE_STRING(ANSI_HIGHLIGHT_RED);
if (on)
iovec[n++] = IOVEC_MAKE_STRING(on);
iovec[n++] = IOVEC_MAKE_STRING(buffer);
if (highlight)
iovec[n++] = IOVEC_MAKE_STRING(ANSI_NORMAL);
if (off)
iovec[n++] = IOVEC_MAKE_STRING(off);
iovec[n++] = IOVEC_MAKE_STRING("\n");
if (writev(console_fd, iovec, n) < 0) {
+38
View File
@@ -1310,3 +1310,41 @@ int vt_release(int fd, bool restore) {
return 0;
}
void get_log_colors(int priority, const char **on, const char **off, const char **highlight) {
/* Note that this will initialize output variables only when there's something to output.
* The caller must pre-initalize to "" or NULL as appropriate. */
if (priority <= LOG_ERR) {
if (on)
*on = ANSI_HIGHLIGHT_RED;
if (off)
*off = ANSI_NORMAL;
if (highlight)
*highlight = ANSI_HIGHLIGHT;
} else if (priority <= LOG_WARNING) {
if (on)
*on = ANSI_HIGHLIGHT_YELLOW;
if (off)
*off = ANSI_NORMAL;
if (highlight)
*highlight = ANSI_HIGHLIGHT;
} else if (priority <= LOG_NOTICE) {
if (on)
*on = ANSI_HIGHLIGHT;
if (off)
*off = ANSI_NORMAL;
if (highlight)
*highlight = ANSI_HIGHLIGHT_RED;
} else if (priority >= LOG_DEBUG) {
if (on)
*on = ANSI_GREY;
if (off)
*off = ANSI_NORMAL;
if (highlight)
*highlight = ANSI_HIGHLIGHT_RED;
}
}
+3
View File
@@ -4,6 +4,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <syslog.h>
#include <sys/types.h>
#include "macro.h"
@@ -158,3 +159,5 @@ int vt_default_utf8(void);
int vt_reset_keyboard(int fd);
int vt_restore(int fd);
int vt_release(int fd, bool restore_vt);
void get_log_colors(int priority, const char **on, const char **off, const char **highlight);