@@ -1105,9 +1105,13 @@ struct json_log_userdata {
11051105 .first
11061106 == field_frag)
11071107 {
1108- return format
1108+ auto retval = format
11091109 ->elf_value_def_read_order [this ->jlu_read_order_index ++]
11101110 .second ;
1111+ if (retval != nullptr ) {
1112+ this ->jlu_precision += 1 ;
1113+ }
1114+ return retval;
11111115 }
11121116
11131117 format->elf_value_def_read_order .resize (this ->jlu_read_order_index );
@@ -1116,6 +1120,9 @@ struct json_log_userdata {
11161120 format->elf_value_def_read_order .emplace_back (vd_iter->first ,
11171121 vd_iter->second );
11181122 this ->jlu_read_order_index += 1 ;
1123+ if (vd_iter->second != nullptr ) {
1124+ this ->jlu_precision += 1 ;
1125+ }
11191126 return vd_iter->second ;
11201127 }
11211128
@@ -1158,6 +1165,7 @@ struct json_log_userdata {
11581165 std::stack<size_t > jlu_sub_start;
11591166 uint32_t jlu_quality{0 };
11601167 uint32_t jlu_strikes{0 };
1168+ uint32_t jlu_precision{0 };
11611169 std::vector<bool > jlu_format_hits;
11621170 shared_buffer_ref& jlu_shared_buffer;
11631171 scan_batch_context* jlu_batch_context;
@@ -1884,7 +1892,7 @@ external_log_format::scan_json(std::vector<logline>& dst,
18841892 if (jlu.jlu_quality > 0 ) {
18851893 jlu.jlu_quality += 3000 ;
18861894 }
1887- return scan_match{jlu.jlu_quality , jlu.jlu_strikes };
1895+ return scan_match{jlu.jlu_quality , jlu.jlu_strikes , jlu. jlu_precision };
18881896}
18891897
18901898log_format::scan_result_t
@@ -2411,9 +2419,37 @@ external_log_format::annotate(logfile* lf,
24112419 }
24122420
24132421 if (cap) {
2414- values.lvv_values .emplace_back (
2415- vd.vd_meta , line, to_line_range (cap.value ()));
2416- values.lvv_values .back ().apply_scaling (scaling);
2422+ if (vd.vd_meta .lvm_kind == value_kind_t ::VALUE_TIMESTAMP ) {
2423+ auto dts = this ->build_time_scanner ();
2424+ exttm tm;
2425+ timeval tv;
2426+ auto val_sf = cap.value ();
2427+
2428+ if (dts.scan (val_sf.data (),
2429+ val_sf.length (),
2430+ this ->get_timestamp_formats (),
2431+ &tm,
2432+ tv,
2433+ true ))
2434+ {
2435+ char ts[64 ];
2436+ tm.et_gmtoff = tm.et_orig_gmtoff ;
2437+ auto len = dts.ftime (
2438+ ts, sizeof (ts), this ->get_timestamp_formats (), tm);
2439+ ts[len] = ' \0 ' ;
2440+ values.lvv_values .emplace_back (vd.vd_meta ,
2441+ std::string{ts, len});
2442+ values.lvv_values .back ().lv_origin
2443+ = to_line_range (cap.value ());
2444+ } else {
2445+ values.lvv_values .emplace_back (
2446+ vd.vd_meta , line, to_line_range (cap.value ()));
2447+ }
2448+ } else {
2449+ values.lvv_values .emplace_back (
2450+ vd.vd_meta , line, to_line_range (cap.value ()));
2451+ values.lvv_values .back ().apply_scaling (scaling);
2452+ }
24172453 } else {
24182454 values.lvv_values .emplace_back (vd.vd_meta );
24192455 }
@@ -2734,6 +2770,35 @@ rewrite_json_field(yajlpp_parse_context* ypc,
27342770 jlu->jlu_format ->get_value_meta (field_name,
27352771 value_kind_t ::VALUE_TEXT ),
27362772 std::string{time_buf});
2773+ } else if (vd != nullptr
2774+ && vd->vd_meta .lvm_kind == value_kind_t ::VALUE_TIMESTAMP )
2775+ {
2776+ auto dts = jlu->jlu_format ->build_time_scanner ();
2777+ exttm tm;
2778+ timeval tv;
2779+
2780+ if (dts.scan ((const char *) str,
2781+ len,
2782+ jlu->jlu_format ->get_timestamp_formats (),
2783+ &tm,
2784+ tv,
2785+ true ))
2786+ {
2787+ char ts[64 ];
2788+ tm.et_gmtoff = tm.et_orig_gmtoff ;
2789+ auto tslen = dts.ftime (
2790+ ts, sizeof (ts), jlu->jlu_format ->get_timestamp_formats (), tm);
2791+ ts[tslen] = ' \0 ' ;
2792+ jlu->jlu_format ->jlf_line_values .lvv_values .emplace_back (
2793+ jlu->jlu_format ->get_value_meta (
2794+ ypc, vd, value_kind_t ::VALUE_TIMESTAMP ),
2795+ std::string{(const char *) ts, tslen});
2796+ } else {
2797+ jlu->jlu_format ->jlf_line_values .lvv_values .emplace_back (
2798+ jlu->jlu_format ->get_value_meta (
2799+ ypc, vd, value_kind_t ::VALUE_TEXT ),
2800+ std::string{(const char *) str, len});
2801+ }
27372802 } else if (jlu->jlu_shared_buffer .contains ((const char *) str)) {
27382803 auto str_offset = (int ) ((const char *) str - jlu->jlu_line_value );
27392804 if (field_name == jlu->jlu_format ->elf_body_field ) {
@@ -2959,31 +3024,6 @@ external_log_format::get_subline(const log_format_file_state& lffs,
29593024 .value ()]
29603025 .get ();
29613026 }
2962- if (lv_iter->lv_meta .lvm_kind
2963- == value_kind_t ::VALUE_TIMESTAMP )
2964- {
2965- auto dts = this ->build_time_scanner ();
2966- exttm tm;
2967- timeval tv;
2968-
2969- if (dts.scan (str.c_str (),
2970- str.size (),
2971- this ->get_timestamp_formats (),
2972- &tm,
2973- tv,
2974- true ))
2975- {
2976- char ts[64 ];
2977- tm.et_gmtoff = tm.et_orig_gmtoff ;
2978- auto len = dts.ftime (
2979- ts,
2980- sizeof (ts),
2981- this ->get_timestamp_formats (),
2982- tm);
2983- ts[len] = ' \0 ' ;
2984- str = ts;
2985- }
2986- }
29873027 while (endswith (str, " \n " )) {
29883028 str.pop_back ();
29893029 }
@@ -3247,31 +3287,6 @@ external_log_format::get_subline(const log_format_file_state& lffs,
32473287 }
32483288
32493289 auto str = lv.to_string ();
3250- if (lv.lv_meta .lvm_kind
3251- == value_kind_t ::VALUE_TIMESTAMP )
3252- {
3253- auto dts = this ->build_time_scanner ();
3254- exttm tm;
3255- timeval tv;
3256-
3257- if (dts.scan (str.c_str (),
3258- str.size (),
3259- this ->get_timestamp_formats (),
3260- &tm,
3261- tv,
3262- true ))
3263- {
3264- char ts[64 ];
3265- tm.et_gmtoff = tm.et_orig_gmtoff ;
3266- auto len = dts.ftime (
3267- ts,
3268- sizeof (ts),
3269- this ->get_timestamp_formats (),
3270- tm);
3271- ts[len] = ' \0 ' ;
3272- str = ts;
3273- }
3274- }
32753290 while (endswith (str, " \n " )) {
32763291 str.pop_back ();
32773292 }
0 commit comments