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
commit e95be7def2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 80 additions and 26 deletions

View file

@ -474,6 +474,7 @@ int main(int argc, char **argv, char **envp) {
int r, n;
int epoll_fd = -1;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -2104,6 +2104,7 @@ static int run(int argc, char *argv[]) {
setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C"); /* we want to format/parse floats in C style */
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -158,6 +158,7 @@ static int run(int argc, char *argv[]) {
char **p;
int r;
log_show_color(true);
log_parse_environment();
log_open();

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) {

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;
}
}

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);

View file

@ -2508,6 +2508,7 @@ static int busctl_main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -165,6 +165,7 @@ static void show_cg_info(const char *controller, const char *path) {
static int run(int argc, char *argv[]) {
int r, output_flags;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -909,6 +909,7 @@ static int run(int argc, char *argv[]) {
CGroupMask mask;
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -1069,6 +1069,7 @@ static int run(int argc, char *argv[]) {
int r, units_active;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -639,6 +639,7 @@ static int parse_argv(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r, k, n_found = 0;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -128,6 +128,7 @@ static int run(int argc, char *argv[]) {
* to detect whether we are being run in a virtualized
* environment or not */
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -159,6 +159,7 @@ static int run(int argc, char *argv[]) {
char **i;
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -432,6 +432,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -155,6 +155,7 @@ static int id128_main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -127,6 +127,7 @@ static int run(int argc, char *argv[]) {
_cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1;
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -2100,6 +2100,7 @@ int main(int argc, char *argv[]) {
int n_shown = 0, r, poll_fd = -1;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -510,6 +510,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -270,6 +270,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -1529,6 +1529,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -3100,6 +3100,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -1515,6 +1515,7 @@ static int run(int argc, char* argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -1128,6 +1128,7 @@ static void warn_networkd_missing(void) {
static int run(int argc, char* argv[]) {
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -151,6 +151,7 @@ static int run(int argc, char* argv[]) {
unsigned i = 0;
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -171,6 +171,7 @@ static int parse_argv(int argc, char *argv[]) {
static int run(int argc, char* argv[]) {
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -956,6 +956,7 @@ static int run(int argc, char *argv[]) {
int r;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -3137,6 +3137,7 @@ static int run(int argc, char **argv) {
int r;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -390,11 +390,10 @@ static int parse_argv(int argc, char *argv[]) {
r = calendar_spec_next_usec(cs, now(CLOCK_REALTIME), NULL);
if (r == -ENOENT)
/* The calendar event is in the past - let's warn about this, but install it
* anyway as it is. The service manager will trigger the service right-away
* then, but everything is discoverable as usual. Moreover, the server side
* might have a different clock or timezone than we do, hence it should
* decide when or whether to run something. */
/* The calendar event is in the past — let's warn about this, but install it
* anyway as is. The service manager will trigger the service right away.
* Moreover, the server side might have a different clock or timezone than we
* do, hence it should decide when or whether to run something. */
log_warning("Specified calendar expression is in the past, proceeding anyway.");
else if (r < 0)
return log_error_errno(r, "Failed to calculate next time calendar expression elapses: %m");
@ -1653,6 +1652,7 @@ static int run(int argc, char* argv[]) {
_cleanup_free_ char *description = NULL;
int r, retval = EXIT_SUCCESS;
log_show_color(true);
log_parse_environment();
log_open();

View file

@ -163,21 +163,8 @@ static bool print_multiline(
bool ellipsized = false;
int line = 0;
if (flags & OUTPUT_COLOR) {
if (priority <= LOG_ERR) {
color_on = ANSI_HIGHLIGHT_RED;
color_off = ANSI_NORMAL;
highlight_on = ANSI_HIGHLIGHT;
} else if (priority <= LOG_NOTICE) {
color_on = ANSI_HIGHLIGHT;
color_off = ANSI_NORMAL;
highlight_on = ANSI_HIGHLIGHT_RED;
} else if (priority >= LOG_DEBUG) {
color_on = ANSI_GREY;
color_off = ANSI_NORMAL;
highlight_on = ANSI_HIGHLIGHT_RED;
}
}
if (flags & OUTPUT_COLOR)
get_log_colors(priority, &color_on, &color_off, &highlight_on);
/* A special case: make sure that we print a newline when
the message is empty. */

View file

@ -866,6 +866,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_show_color(true);
log_parse_environment();
log_open();