From 8d703970051326b0d9e881de3d0e63c138123740 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Thu, 28 Mar 2024 14:28:32 -0700 Subject: [PATCH] [jsonl] pay attention to min width for abbrev overflow method Related to #1237 --- src/log_format.cc | 32 ++++++++-------- ...8cac40c27f547044c89d39eb0ff2ef81da4b21.out | 4 +- ...223ac4742883f883ccc61044bfffd6e102cca6.out | 13 +++++++ ...9f005b0708d629bc95f0c48a5e390f440c1fef.out | 4 +- ...d03b1b41a7f819af135d2521a8f2c59418e907.out | 28 +++++++------- ...6b3cdd46b387e72d6faa4cce648b8b11ae870b.out | 4 +- ...40026626ab554dacb249762d8be7d6539b8c6e.out | 2 +- ...f252288519c8f767bb2759ea32959dab2ebc46.out | 38 ++++++++++++++++++- test/formats/jsontest/format.json | 13 +++++++ test/logfile_json.json | 4 +- 10 files changed, 100 insertions(+), 42 deletions(-) diff --git a/src/log_format.cc b/src/log_format.cc index 82c5aacf..7c0b6b8b 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -2130,6 +2130,14 @@ external_log_format::get_subline(const logline& ll, logline_value_cmp(&jfe.jfe_value.pp_value)); if (lv_iter != this->jlf_line_values.lvv_values.end()) { auto str = lv_iter->to_string(); + value_def* vd = nullptr; + + if (lv_iter->lv_meta.lvm_values_index) { + vd = this->elf_value_def_order + [lv_iter->lv_meta.lvm_values_index + .value()] + .get(); + } while (endswith(str, "\n")) { str.pop_back(); } @@ -2144,15 +2152,13 @@ external_log_format::get_subline(const logline& ll, switch (jfe.jfe_overflow) { case json_format_element::overflow_t:: ABBREV: { - this->json_append_to_cache(str.c_str(), - str.size()); - size_t new_size = abbreviate_str( - &this->jlf_cached_line[lr.lr_start], - str.size(), - jfe.jfe_max_width); - - this->jlf_cached_line.resize( - lr.lr_start + new_size); + size_t new_size + = abbreviate_str(&str[0], + str.size(), + jfe.jfe_max_width); + str.resize(new_size); + this->json_append( + jfe, vd, str.data(), str.size()); break; } case json_format_element::overflow_t:: @@ -2177,14 +2183,6 @@ external_log_format::get_subline(const logline& ll, } } } else { - value_def* vd = nullptr; - - if (lv_iter->lv_meta.lvm_values_index) { - vd = this->elf_value_def_order - [lv_iter->lv_meta.lvm_values_index - .value()] - .get(); - } sub_offset += std::count(str.begin(), str.end(), '\n'); this->json_append( diff --git a/test/expected/test_json_format.sh_168cac40c27f547044c89d39eb0ff2ef81da4b21.out b/test/expected/test_json_format.sh_168cac40c27f547044c89d39eb0ff2ef81da4b21.out index 96ded5f3..dd6c9d25 100644 --- a/test/expected/test_json_format.sh_168cac40c27f547044c89d39eb0ff2ef81da4b21.out +++ b/test/expected/test_json_format.sh_168cac40c27f547044c89d39eb0ff2ef81da4b21.out @@ -1,5 +1,5 @@ -{"ts": "2013-09-06T20:00:48.124817Z", "lvl": "TRACE", "msg": "trace test"} -{"ts": "2013-09-06T20:00:49.124817Z", "lvl": "INFO", "msg": "Starting up \u001B[0;32mservice\u001B[0m"} +{"ts": "2013-09-06T20:00:48.124817Z", "logger": "com.example.foo.bar.bazzer", "lvl": "TRACE", "msg": "trace test"} +{"ts": "2013-09-06T20:00:49.124817Z", "logger": "com.example.demo", "lvl": "INFO", "msg": "Starting up \u001B[0;32mservice\u001B[0m"} {"ts": "2013-09-06T22:00:49.124817Z", "lvl": "INFO", "msg": "Shutting down service", "user": "steve@example.com"} {"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG5", "msg": "D\bDetails...\n"} {"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG4", "msg": "D\bDe\betails...\n"} diff --git a/test/expected/test_json_format.sh_40223ac4742883f883ccc61044bfffd6e102cca6.out b/test/expected/test_json_format.sh_40223ac4742883f883ccc61044bfffd6e102cca6.out index 75b8ea39..53d473d1 100644 --- a/test/expected/test_json_format.sh_40223ac4742883f883ccc61044bfffd6e102cca6.out +++ b/test/expected/test_json_format.sh_40223ac4742883f883ccc61044bfffd6e102cca6.out @@ -5,6 +5,7 @@ "log_level": "trace", "arr": null, "obj": null, + "logger": "com.example.foo.bar.bazzer", "lvl": "TRACE", "user": null, "log_part": null, @@ -21,6 +22,7 @@ "log_level": "info", "arr": null, "obj": null, + "logger": "com.example.demo", "lvl": "INFO", "user": null, "log_part": null, @@ -37,6 +39,7 @@ "log_level": "info", "arr": null, "obj": null, + "logger": null, "lvl": "INFO", "user": "steve@example.com", "log_part": null, @@ -53,6 +56,7 @@ "log_level": "debug5", "arr": null, "obj": null, + "logger": null, "lvl": "DEBUG5", "user": null, "log_part": null, @@ -69,6 +73,7 @@ "log_level": "debug4", "arr": null, "obj": null, + "logger": null, "lvl": "DEBUG4", "user": null, "log_part": null, @@ -85,6 +90,7 @@ "log_level": "debug3", "arr": null, "obj": null, + "logger": null, "lvl": "DEBUG3", "user": null, "log_part": null, @@ -101,6 +107,7 @@ "log_level": "debug2", "arr": null, "obj": null, + "logger": null, "lvl": "DEBUG2", "user": null, "log_part": null, @@ -117,6 +124,7 @@ "log_level": "debug", "arr": null, "obj": null, + "logger": null, "lvl": "DEBUG", "user": null, "log_part": null, @@ -133,6 +141,7 @@ "log_level": "stats", "arr": null, "obj": null, + "logger": null, "lvl": "STATS", "user": null, "log_part": null, @@ -149,6 +158,7 @@ "log_level": "warning", "arr": null, "obj": null, + "logger": null, "lvl": "WARNING", "user": null, "log_part": null, @@ -165,6 +175,7 @@ "log_level": "error", "arr": null, "obj": null, + "logger": null, "lvl": "ERROR", "user": null, "log_part": null, @@ -181,6 +192,7 @@ "log_level": "critical", "arr": null, "obj": null, + "logger": null, "lvl": "CRITICAL", "user": null, "log_part": null, @@ -205,6 +217,7 @@ "field1": "hi", "field2": 2 }, + "logger": null, "lvl": "FATAL", "user": null, "log_part": null, diff --git a/test/expected/test_json_format.sh_469f005b0708d629bc95f0c48a5e390f440c1fef.out b/test/expected/test_json_format.sh_469f005b0708d629bc95f0c48a5e390f440c1fef.out index ad4b0dbc..5ac8979a 100644 --- a/test/expected/test_json_format.sh_469f005b0708d629bc95f0c48a5e390f440c1fef.out +++ b/test/expected/test_json_format.sh_469f005b0708d629bc95f0c48a5e390f440c1fef.out @@ -1,7 +1,7 @@ -[2013-09-06T20:00:48.124] ⋮ trace test +[2013-09-06T20:00:48.124] ⋮ trace test -[2013-09-06T20:00:49.124] ⋮ Starting up service +[2013-09-06T20:00:49.124] ⋮ Starting up service [2013-09-06T22:00:49.124] ⋮ Shutting down service user: steve@example.com diff --git a/test/expected/test_json_format.sh_85d03b1b41a7f819af135d2521a8f2c59418e907.out b/test/expected/test_json_format.sh_85d03b1b41a7f819af135d2521a8f2c59418e907.out index e24a3b0a..48ec77cd 100644 --- a/test/expected/test_json_format.sh_85d03b1b41a7f819af135d2521a8f2c59418e907.out +++ b/test/expected/test_json_format.sh_85d03b1b41a7f819af135d2521a8f2c59418e907.out @@ -1,14 +1,14 @@ -log_line,log_time,log_level,arr,obj,lvl,user,log_part,log_idle_msecs,log_mark,log_comment,log_tags,log_annotations,log_filters -0,2013-09-06 20:00:48.124,trace,,,TRACE,,,0,0,,,, -2,2013-09-06 20:00:49.124,info,,,INFO,,,1000,0,,,, -4,2013-09-06 22:00:49.124,info,,,INFO,steve@example.com,,7200000,0,,,, -7,2013-09-06 22:00:59.124,debug5,,,DEBUG5,,,10000,0,,,, -9,2013-09-06 22:00:59.124,debug4,,,DEBUG4,,,0,0,,,, -11,2013-09-06 22:00:59.124,debug3,,,DEBUG3,,,0,0,,,, -13,2013-09-06 22:00:59.124,debug2,,,DEBUG2,,,0,0,,,, -15,2013-09-06 22:01:00.000,debug,,,DEBUG,,,876,0,,,, -17,2013-09-06 22:01:49.124,stats,,,STATS,,,49124,0,,,, -19,2013-09-06 22:01:49.124,warning,,,WARNING,,,0,0,,,, -21,2013-09-06 22:01:49.124,error,,,ERROR,,,0,0,,,, -23,2013-09-06 22:01:49.124,critical,,,CRITICAL,,,0,0,,,, -25,2013-09-06 22:01:49.124,fatal,"[""hi"", {""sub1"": true}]","{ ""field1"" : ""hi"", ""field2"": 2 }",FATAL,,,0,0,,,, +log_line,log_time,log_level,arr,obj,logger,lvl,user,log_part,log_idle_msecs,log_mark,log_comment,log_tags,log_annotations,log_filters +0,2013-09-06 20:00:48.124,trace,,,com.example.foo.bar.bazzer,TRACE,,,0,0,,,, +2,2013-09-06 20:00:49.124,info,,,com.example.demo,INFO,,,1000,0,,,, +4,2013-09-06 22:00:49.124,info,,,,INFO,steve@example.com,,7200000,0,,,, +7,2013-09-06 22:00:59.124,debug5,,,,DEBUG5,,,10000,0,,,, +9,2013-09-06 22:00:59.124,debug4,,,,DEBUG4,,,0,0,,,, +11,2013-09-06 22:00:59.124,debug3,,,,DEBUG3,,,0,0,,,, +13,2013-09-06 22:00:59.124,debug2,,,,DEBUG2,,,0,0,,,, +15,2013-09-06 22:01:00.000,debug,,,,DEBUG,,,876,0,,,, +17,2013-09-06 22:01:49.124,stats,,,,STATS,,,49124,0,,,, +19,2013-09-06 22:01:49.124,warning,,,,WARNING,,,0,0,,,, +21,2013-09-06 22:01:49.124,error,,,,ERROR,,,0,0,,,, +23,2013-09-06 22:01:49.124,critical,,,,CRITICAL,,,0,0,,,, +25,2013-09-06 22:01:49.124,fatal,"[""hi"", {""sub1"": true}]","{ ""field1"" : ""hi"", ""field2"": 2 }",,FATAL,,,0,0,,,, diff --git a/test/expected/test_json_format.sh_a06b3cdd46b387e72d6faa4cce648b8b11ae870b.out b/test/expected/test_json_format.sh_a06b3cdd46b387e72d6faa4cce648b8b11ae870b.out index bfb866a7..f1f02034 100644 --- a/test/expected/test_json_format.sh_a06b3cdd46b387e72d6faa4cce648b8b11ae870b.out +++ b/test/expected/test_json_format.sh_a06b3cdd46b387e72d6faa4cce648b8b11ae870b.out @@ -1,7 +1,7 @@ -[2013-09-06T20:00:48.124000Z] ⋮ trace testbork bork bork +[2013-09-06T20:00:48.124000Z] ⋮ trace testbork bork bork -[2013-09-06T20:00:49.124000Z] ⋮ Starting up servicebork bork bork +[2013-09-06T20:00:49.124000Z] ⋮ Starting up servicebork bork bork [2013-09-06T22:00:49.124000Z] ⋮ Shutting down servicebork bork bork user: mailto:steve@example.com diff --git a/test/expected/test_json_format.sh_f740026626ab554dacb249762d8be7d6539b8c6e.out b/test/expected/test_json_format.sh_f740026626ab554dacb249762d8be7d6539b8c6e.out index 54b98d87..31775359 100644 --- a/test/expected/test_json_format.sh_f740026626ab554dacb249762d8be7d6539b8c6e.out +++ b/test/expected/test_json_format.sh_f740026626ab554dacb249762d8be7d6539b8c6e.out @@ -1,2 +1,2 @@ -[2013-09-06T20:00:49.124] ⋮ Starting up service +[2013-09-06T20:00:49.124] ⋮ Starting up service diff --git a/test/expected/test_text_file.sh_78f252288519c8f767bb2759ea32959dab2ebc46.out b/test/expected/test_text_file.sh_78f252288519c8f767bb2759ea32959dab2ebc46.out index 658fee40..97ad4bc6 100644 --- a/test/expected/test_text_file.sh_78f252288519c8f767bb2759ea32959dab2ebc46.out +++ b/test/expected/test_text_file.sh_78f252288519c8f767bb2759ea32959dab2ebc46.out @@ -2,7 +2,7 @@ { "top_meta": { "file": "{test_dir}/formats/jsontest/format.json", - "anchor": "#/test_log/timestamp-field", + "anchor": "#/test_log/line-format/4/overflow", "breadcrumbs": [ { "display_value": "format.json", @@ -26,7 +26,7 @@ ] }, { - "display_value": "timestamp-field", + "display_value": "line-format", "search_placeholder": "", "possibilities": [ { @@ -57,6 +57,40 @@ "display_value": "value" } ] + }, + { + "display_value": "[4]", + "search_placeholder": "(Enter a number from 0 to 6)", + "possibilities": [ + + ] + }, + { + "display_value": "overflow", + "search_placeholder": "", + "possibilities": [ + { + "display_value": "default-value" + }, + { + "display_value": "field" + }, + { + "display_value": "max-width" + }, + { + "display_value": "min-width" + }, + { + "display_value": "overflow" + }, + { + "display_value": "prefix" + }, + { + "display_value": "suffix" + } + ] } ] } diff --git a/test/formats/jsontest/format.json b/test/formats/jsontest/format.json index 333b8a9b..63148ea9 100644 --- a/test/formats/jsontest/format.json +++ b/test/formats/jsontest/format.json @@ -15,6 +15,15 @@ "field": "lvl", "auto-width": true }, + { + "field": "logger", + "prefix": " <", + "suffix": ">", + "min-width": 20, + "max-width": 20, + "overflow": "abbrev", + "default-value": "" + }, " ", { "field": "msg" @@ -33,6 +42,10 @@ "obj": { "kind": "json" }, + "logger": { + "kind": "string", + "identifier": true + }, "lvl": { "kind": "string", "hidden": true diff --git a/test/logfile_json.json b/test/logfile_json.json index 96ded5f3..dd6c9d25 100644 --- a/test/logfile_json.json +++ b/test/logfile_json.json @@ -1,5 +1,5 @@ -{"ts": "2013-09-06T20:00:48.124817Z", "lvl": "TRACE", "msg": "trace test"} -{"ts": "2013-09-06T20:00:49.124817Z", "lvl": "INFO", "msg": "Starting up \u001B[0;32mservice\u001B[0m"} +{"ts": "2013-09-06T20:00:48.124817Z", "logger": "com.example.foo.bar.bazzer", "lvl": "TRACE", "msg": "trace test"} +{"ts": "2013-09-06T20:00:49.124817Z", "logger": "com.example.demo", "lvl": "INFO", "msg": "Starting up \u001B[0;32mservice\u001B[0m"} {"ts": "2013-09-06T22:00:49.124817Z", "lvl": "INFO", "msg": "Shutting down service", "user": "steve@example.com"} {"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG5", "msg": "D\bDetails...\n"} {"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG4", "msg": "D\bDe\betails...\n"}