X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Flogs-show.c;h=2270c3b0305913109f57760dc349c37b53fdf4a9;hb=b4b02cbeec04b51697bce1f4e439b9b7afae5393;hp=bd7363aa82a2888f6efa183f4423ac3fbe454fb4;hpb=44bc6e1fe0171af19451b5586f7fdd08853ccf5b;p=elogind.git diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index bd7363aa8..2270c3b03 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -101,10 +101,11 @@ static bool shall_print(const char *p, size_t l, OutputFlags flags) { return true; } -static void print_multiline(FILE *f, unsigned prefix, unsigned n_columns, OutputMode flags, int priority, const char* message, size_t message_len) { +static bool print_multiline(FILE *f, unsigned prefix, unsigned n_columns, OutputMode flags, int priority, const char* message, size_t message_len) { const char *color_on = "", *color_off = ""; const char *pos, *end; bool continuation = false; + bool ellipsized = false; if (flags & OUTPUT_COLOR) { if (priority <= LOG_ERR) { @@ -130,17 +131,26 @@ static void print_multiline(FILE *f, unsigned prefix, unsigned n_columns, Output else if (prefix < n_columns && n_columns - prefix >= 3) { _cleanup_free_ char *e; + ellipsized = true; e = ellipsize_mem(pos, len, n_columns - prefix, 90); if (!e) - fprintf(f, "%s%.*s%s\n", color_on, len, pos, color_off); + fprintf(f, "%*s%s%.*s%s\n", + continuation * prefix, "", + color_on, len, pos, color_off); else - fprintf(f, "%s%s%s\n", color_on, e, color_off); - } else + fprintf(f, "%*s%s%s%s\n", + continuation * prefix, "", + color_on, e, color_off); + } else { + ellipsized = true; fputs("...\n", f); + } continuation = true; } + + return ellipsized; } static int output_short( @@ -157,11 +167,12 @@ static int output_short( _cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL; size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0; int p = LOG_INFO; + bool ellipsized = false; assert(f); assert(j); - sd_journal_set_data_threshold(j, flags & OUTPUT_SHOW_ALL ? 0 : PRINT_THRESHOLD); + sd_journal_set_data_threshold(j, flags & (OUTPUT_SHOW_ALL|OUTPUT_FULL_WIDTH) ? 0 : PRINT_THRESHOLD); JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) { @@ -314,13 +325,14 @@ static int output_short( fprintf(f, ": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len)); } else { fputs(": ", f); - print_multiline(f, n + 2, n_columns, flags, p, message, message_len); + ellipsized |= + print_multiline(f, n + 2, n_columns, flags, p, message, message_len); } if (flags & OUTPUT_CATALOG) print_catalog(f, j); - return 0; + return ellipsized; } static int output_verbose( @@ -817,7 +829,8 @@ int output_journal( sd_journal *j, OutputMode mode, unsigned n_columns, - OutputFlags flags) { + OutputFlags flags, + bool *ellipsized) { int ret; assert(mode >= 0); @@ -828,6 +841,10 @@ int output_journal( ret = output_funcs[mode](f, j, mode, n_columns, flags); fflush(stdout); + + if (ellipsized && ret > 0) + *ellipsized = true; + return ret; } @@ -837,7 +854,8 @@ static int show_journal(FILE *f, unsigned n_columns, usec_t not_before, unsigned how_many, - OutputFlags flags) { + OutputFlags flags, + bool *ellipsized) { int r; unsigned line = 0; @@ -888,7 +906,7 @@ static int show_journal(FILE *f, line ++; - r = output_journal(f, j, mode, n_columns, flags); + r = output_journal(f, j, mode, n_columns, flags, ellipsized); if (r < 0) goto finish; } @@ -1037,7 +1055,8 @@ int show_journal_by_unit( unsigned how_many, uid_t uid, OutputFlags flags, - bool system) { + bool system, + bool *ellipsized) { _cleanup_journal_close_ sd_journal*j = NULL; int r; @@ -1072,11 +1091,7 @@ int show_journal_by_unit( log_debug("Journal filter: %s", filter); } - r = show_journal(f, j, mode, n_columns, not_before, how_many, flags); - if (r < 0) - return r; - - return 0; + return show_journal(f, j, mode, n_columns, not_before, how_many, flags, ellipsized); } static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {