chiark / gitweb /
share/log: skip file/line/func info if empty
[elogind.git] / src / shared / logs-show.c
index cb93761bd19d83f191229932957ee9b00d1e5aa0..c221af3de5fb6cd676b54af8d1b127fed777b4f2 100644 (file)
@@ -91,7 +91,7 @@ static bool shall_print(const char *p, size_t l, OutputFlags flags) {
         if (flags & OUTPUT_SHOW_ALL)
                 return true;
 
-        if (l > PRINT_THRESHOLD)
+        if (l >= PRINT_THRESHOLD)
                 return false;
 
         if (!utf8_is_printable_n(p, l))
@@ -119,6 +119,8 @@ static int output_short(
         assert(f);
         assert(j);
 
+        sd_journal_set_data_threshold(j, flags & OUTPUT_SHOW_ALL ? 0 : PRINT_THRESHOLD);
+
         SD_JOURNAL_FOREACH_DATA(j, data, length) {
 
                 r = parse_field(data, length, "PRIORITY=", &priority, &priority_len);
@@ -177,6 +179,9 @@ static int output_short(
         if (!message)
                 return 0;
 
+        if (!(flags & OUTPUT_SHOW_ALL))
+                strip_tab_ansi(&message, &message_len);
+
         if (priority_len == 1 && *priority >= '0' && *priority <= '7')
                 p = *priority - '0';
 
@@ -272,7 +277,7 @@ static int output_short(
         } else if ((flags & OUTPUT_FULL_WIDTH) || (message_len + n + 1 < n_columns))
                 fprintf(f, ": %s%.*s%s\n", color_on, (int) message_len, message, color_off);
         else if (n < n_columns && n_columns - n - 2 >= 3) {
-                char *e;
+                char _cleanup_free_ *e;
 
                 e = ellipsize_mem(message, message_len, n_columns - n - 2, 90);
 
@@ -280,8 +285,6 @@ static int output_short(
                         fprintf(f, ": %s%.*s%s\n", color_on, (int) message_len, message, color_off);
                 else
                         fprintf(f, ": %s%s%s\n", color_on, e, color_off);
-
-                free(e);
         } else
                 fputs("\n", f);
 
@@ -300,7 +303,7 @@ static int output_verbose(
 
         const void *data;
         size_t length;
-        char *cursor;
+        char _cleanup_free_ *cursor = NULL;
         uint64_t realtime;
         char ts[FORMAT_TIMESTAMP_MAX];
         int r;
@@ -308,6 +311,8 @@ static int output_verbose(
         assert(f);
         assert(j);
 
+        sd_journal_set_data_threshold(j, 0);
+
         r = sd_journal_get_realtime_usec(j, &realtime);
         if (r < 0) {
                 log_error("Failed to get realtime timestamp: %s", strerror(-r));
@@ -324,8 +329,6 @@ static int output_verbose(
                 format_timestamp(ts, sizeof(ts), realtime),
                 cursor);
 
-        free(cursor);
-
         SD_JOURNAL_FOREACH_DATA(j, data, length) {
                 if (!shall_print(data, length, flags)) {
                         const char *c;
@@ -362,12 +365,14 @@ static int output_export(
         char sid[33];
         int r;
         usec_t realtime, monotonic;
-        char *cursor;
+        char _cleanup_free_ *cursor = NULL;
         const void *data;
         size_t length;
 
         assert(j);
 
+        sd_journal_set_data_threshold(j, 0);
+
         r = sd_journal_get_realtime_usec(j, &realtime);
         if (r < 0) {
                 log_error("Failed to get realtime timestamp: %s", strerror(-r));
@@ -396,8 +401,6 @@ static int output_export(
                 (unsigned long long) monotonic,
                 sd_id128_to_string(boot_id, sid));
 
-        free(cursor);
-
         SD_JOURNAL_FOREACH_DATA(j, data, length) {
 
                 /* We already printed the boot id, from the data in
@@ -441,7 +444,7 @@ void json_escape(
         assert(f);
         assert(p);
 
-        if (!(flags & OUTPUT_SHOW_ALL) && l > JSON_THRESHOLD)
+        if (!(flags & OUTPUT_SHOW_ALL) && l >= JSON_THRESHOLD)
 
                 fputs("null", f);
 
@@ -491,17 +494,19 @@ static int output_json(
                 OutputFlags flags) {
 
         uint64_t realtime, monotonic;
-        char *cursor, *k;
+        char _cleanup_free_ *cursor = NULL;
         const void *data;
         size_t length;
         sd_id128_t boot_id;
-        char sid[33];
+        char sid[33], *k;
         int r;
         Hashmap *h = NULL;
         bool done, separator;
 
         assert(j);
 
+        sd_journal_set_data_threshold(j, flags & OUTPUT_SHOW_ALL ? 0 : JSON_THRESHOLD);
+
         r = sd_journal_get_realtime_usec(j, &realtime);
         if (r < 0) {
                 log_error("Failed to get realtime timestamp: %s", strerror(-r));
@@ -545,7 +550,6 @@ static int output_json(
                         (unsigned long long) monotonic,
                         sd_id128_to_string(boot_id, sid));
         }
-        free(cursor);
 
         h = hashmap_new(string_hash_func, string_compare_func);
         if (!h)
@@ -714,6 +718,8 @@ static int output_cat(
         assert(j);
         assert(f);
 
+        sd_journal_set_data_threshold(j, 0);
+
         r = sd_journal_get_data(j, "MESSAGE", &data, &l);
         if (r < 0) {
                 /* An entry without MESSAGE=? */