Skip to content

Commit d28bb8e

Browse files
committed
[pretty] if JSON log body is not in line-format, still need to pretty print
1 parent 6cf3580 commit d28bb8e

9 files changed

Lines changed: 32 additions & 20 deletions

src/base/string_attr_type.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
constexpr string_attr_type<void> SA_ORIGINAL_LINE("original_line");
3535
constexpr string_attr_type<void> SA_BODY("body");
36+
constexpr string_attr_type<void> SA_EXTRA_CONTENT("extra-content");
3637
constexpr string_attr_type<ui_icon_t> SA_HIDDEN("hidden");
3738
constexpr string_attr_type<void> SA_REPLACED("replaced");
3839
constexpr string_attr_type<intern_string_t> SA_FORMAT("format");

src/base/string_attr_type.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ public:
400400

401401
extern const string_attr_type<void> SA_ORIGINAL_LINE;
402402
extern const string_attr_type<void> SA_BODY;
403+
extern const string_attr_type<void> SA_EXTRA_CONTENT;
403404
extern const string_attr_type<ui_icon_t> SA_HIDDEN;
404405
extern const string_attr_type<void> SA_REPLACED;
405406
extern const string_attr_type<intern_string_t> SA_FORMAT;

src/log_format.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,16 @@ external_log_format::get_subline(const logline& ll,
28022802
this->json_append_to_cache(
28032803
lv.lv_meta.lvm_name.to_string_fragment());
28042804
this->json_append_to_cache(": ", 2);
2805+
lr.lr_start = this->jlf_cached_line.size();
28052806
this->json_append_to_cache(utf_scan_res.usr_valid_frag);
2807+
lr.lr_end = this->jlf_cached_line.size();
2808+
if (lv.lv_meta.lvm_name == this->elf_body_field) {
2809+
this->jlf_line_attrs.emplace_back(lr, SA_BODY.value());
2810+
2811+
} else {
2812+
this->jlf_line_attrs.emplace_back(
2813+
lr, SA_EXTRA_CONTENT.value());
2814+
}
28062815
this->json_append_to_cache("\n", 1);
28072816
sub_offset += 1;
28082817
if (utf_scan_res.usr_remaining) {

src/view_helpers.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ open_pretty_view()
454454
// TODO: dump more details of the line in the output.
455455
pp.append_to(pretty_al);
456456
} else {
457+
log_info("skipping pretty-print of log message with no body");
457458
pretty_al = orig_al;
458459
}
459460

test/expected/test_json_format.sh_469f005b0708d629bc95f0c48a5e390f440c1fef.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
[2013-09-06T22:01:49.124817Z] ⋮ sooo bad
2626

2727
[2013-09-06T22:01:49.124817Z] ⋮ shoot
28-
 obj: { "field1" : "hi", "field2": 2 }
29-
 arr: ["hi", {"sub1": true}]
28+
 obj: { "field1" : "hi", "field2": 2 }
29+
 arr: ["hi", {"sub1": true}]

test/expected/test_json_format.sh_7724d1a96d74d4418dd44d7416270f9bb64b2564.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
2013-09-06T22:01:49.124817Z STATS 1 beat per second
1919
@fields: { "lvl": "STATS", "msg": "1 beat per second"}
2020
2013-09-06T22:01:49.124817Z WARNING not looking good
21-
 @fields: { "lvl": "WARNING", "msg": "not looking good"}
21+
 @fields: { "lvl": "WARNING", "msg": "not looking good"}
2222
2013-09-06T22:01:49.124817Z ERROR looking bad
23-
 @fields: { "lvl": "ERROR", "msg": "looking bad"}
23+
 @fields: { "lvl": "ERROR", "msg": "looking bad"}
2424
2013-09-06T22:01:49.124817Z CRITICAL sooo bad
25-
 @fields: { "lvl": "CRITICAL", "msg": "sooo bad"}
25+
 @fields: { "lvl": "CRITICAL", "msg": "sooo bad"}
2626
2013-09-06T22:01:49.124817Z FATAL shoot
27-
 @fields/trace#: line:1
28-
 @fields/trace#: line:2
29-
 @fields: { "lvl": "FATAL", "msg": "shoot", "trace": ["line:1", "line:2"]}
27+
 @fields/trace#: line:1
28+
 @fields/trace#: line:2
29+
 @fields: { "lvl": "FATAL", "msg": "shoot", "trace": ["line:1", "line:2"]}

test/expected/test_json_format.sh_8f2ebcd319afc7966ef11e31f9dd646bf6f001dd.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ panic: foo bar failed baz
1717
⋮ abc 49 def ERROR - looking bad
1818
⋮ abc 49 def CRITICAL - sooo bad
1919
⋮ abc 49 def FATAL - shoot
20-
 obj: { "field1" : "hi", "field2": 2 }
21-
 arr: ["hi", {"sub1": true}]
20+
 obj: { "field1" : "hi", "field2": 2 }
21+
 arr: ["hi", {"sub1": true}]

test/expected/test_json_format.sh_c60050b3469f37c5b0864e1dc7eb354e91d6ec81.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
3737
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
3838
 ... 33 common frames omitted
39-
 @version: 1
39+
 @version: 1
4040
 logger_name: org.apache.jasper.runtime.JspFactoryImpl
41-
 thread_name: http-bio-0.0.0.0-8081-exec-198
42-
 level: ERROR
43-
 customer: foobaz
41+
 thread_name: http-bio-0.0.0.0-8081-exec-198
42+
 level: ERROR
43+
 customer: foobaz
4444
2016-08-03T17:06:31.009+0000 - ;Exception initializing page context; 
45-
 @version: 1
45+
 @version: 1
4646
 logger_name: org.apache.jasper.runtime.JspFactoryImpl
47-
 thread_name: http-bio-0.0.0.0-8081-exec-198
48-
 level: ERROR
49-
 customer: foobaz
47+
 thread_name: http-bio-0.0.0.0-8081-exec-198
48+
 level: ERROR
49+
 customer: foobaz

test/expected/test_json_format.sh_eb316389dd36295ceebfa23cf39727fa8314fa91.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
[2013-09-06T18:01:49.124817-0400] ⋮ sooo bad
2626

2727
[2013-09-06T18:01:49.124817-0400] ⋮ shoot
28-
 obj: { "field1" : "hi", "field2": 2 }
29-
 arr: ["hi", {"sub1": true}]
28+
 obj: { "field1" : "hi", "field2": 2 }
29+
 arr: ["hi", {"sub1": true}]

0 commit comments

Comments
 (0)