Skip to content

Commit dd07841

Browse files
committed
[log_format] support combined file/line location field
1 parent cfd0378 commit dd07841

8 files changed

Lines changed: 47 additions & 4 deletions

File tree

NEWS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ Features:
8282
statements.
8383
- Log formats can now specify source file/line and
8484
thread ID with the `src-file-field`, `src-line-field`,
85-
and `thread-id-field` properties. These fields can
86-
then be accessed in the SQL vtables as `log_src_file`,
87-
`log_src_line`, and `log_thread_id`.
85+
`src-location-field`, and `thread-id-field` properties.
86+
These fields can then be accessed in the SQL vtables
87+
as `log_src_file`, `log_src_line`, and `log_thread_id`.
8888
- The `:breakpoint`, `:toggle-breakpoint`, and
8989
`:clear-breakpoints` commands have been added to
9090
support setting/clearing breakpoints for log messages.

docs/schemas/format-v1.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@
179179
"description": "The name of the source line field in the log message pattern",
180180
"type": "string"
181181
},
182+
"src-location-field": {
183+
"title": "/<format_name>/src-location-field",
184+
"description": "The name of the field that contains the source file and line number",
185+
"type": "string"
186+
},
182187
"duration-field": {
183188
"title": "/<format_name>/duration-field",
184189
"description": "The name of the duration field in the log message pattern",

src/base/string_attr_type.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ constexpr string_attr_type<void> SA_ORIGINAL_LINE("original_line");
3535
constexpr string_attr_type<void> SA_BODY("body");
3636
constexpr string_attr_type<void> SA_SRC_FILE("src-file");
3737
constexpr string_attr_type<void> SA_SRC_LINE("src-line");
38+
constexpr string_attr_type<void> SA_SRC_LOC("src-loc");
3839
constexpr string_attr_type<void> SA_THREAD_ID("thread-id");
3940
constexpr string_attr_type<void> SA_DURATION("duration");
4041
constexpr string_attr_type<void> SA_EXTRA_CONTENT("extra-content");
@@ -53,7 +54,7 @@ constexpr string_attr_type<std::string> VC_ANCHOR("anchor");
5354
constexpr string_attr_type<role_t> VC_ROLE("role");
5455
constexpr string_attr_type<role_t> VC_ROLE_FG("role-fg");
5556
constexpr string_attr_type<text_attrs> VC_STYLE("style");
56-
constexpr string_attr_type<const char *> VC_GRAPHIC("graphic");
57+
constexpr string_attr_type<const char*> VC_GRAPHIC("graphic");
5758
constexpr string_attr_type<block_elem_t> VC_BLOCK_ELEM("block-elem");
5859
constexpr string_attr_type<styling::color_unit> VC_FOREGROUND("foreground");
5960
constexpr string_attr_type<styling::color_unit> VC_BACKGROUND("background");

src/base/string_attr_type.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ extern const string_attr_type<void> SA_ORIGINAL_LINE;
417417
extern const string_attr_type<void> SA_BODY;
418418
extern const string_attr_type<void> SA_SRC_FILE;
419419
extern const string_attr_type<void> SA_SRC_LINE;
420+
extern const string_attr_type<void> SA_SRC_LOC;
420421
extern const string_attr_type<void> SA_THREAD_ID;
421422
extern const string_attr_type<void> SA_DURATION;
422423
extern const string_attr_type<void> SA_EXTRA_CONTENT;

src/log_format.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,31 @@ external_log_format::get_subline(const log_format_file_state& lffs,
31143114
{
31153115
this->jlf_attr_line.al_attrs.emplace_back(
31163116
lr, SA_BODY.value());
3117+
} else if (lv_iter->lv_meta.lvm_name
3118+
== this->elf_src_loc_field)
3119+
{
3120+
size_t digits = 0;
3121+
for (auto str_iter = str.rbegin();
3122+
str_iter != str.rend();
3123+
++str_iter)
3124+
{
3125+
if (isdigit(*str_iter)) {
3126+
digits += 1;
3127+
} else {
3128+
break;
3129+
}
3130+
}
3131+
auto diff = str.size() - digits;
3132+
auto file_lr = lr;
3133+
file_lr.lr_end -= digits + 1;
3134+
auto line_lr = lr;
3135+
line_lr.lr_start += diff;
3136+
this->jlf_attr_line.al_attrs.emplace_back(
3137+
lr, SA_SRC_LOC.value());
3138+
this->jlf_attr_line.al_attrs.emplace_back(
3139+
file_lr, SA_SRC_FILE.value());
3140+
this->jlf_attr_line.al_attrs.emplace_back(
3141+
line_lr, SA_SRC_LINE.value());
31173142
} else if (lv_iter->lv_meta.lvm_name
31183143
== this->elf_src_file_field)
31193144
{

src/log_format_ext.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public:
359359
intern_string_t elf_thread_id_field;
360360
intern_string_t elf_src_file_field;
361361
intern_string_t elf_src_line_field;
362+
intern_string_t elf_src_loc_field;
362363
intern_string_t elf_duration_field;
363364
std::map<log_level_t, level_pattern> elf_level_patterns;
364365
std::vector<std::pair<int64_t, log_level_t>> elf_level_pairs;

src/log_format_loader.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,10 @@ const struct json_path_container format_handlers = {
10701070
.with_description(
10711071
"The name of the source line field in the log message pattern")
10721072
.for_field(&external_log_format::elf_src_line_field),
1073+
json_path_handler("src-location-field")
1074+
.with_description("The name of the field that contains the source file "
1075+
"and line number")
1076+
.for_field(&external_log_format::elf_src_loc_field),
10731077
json_path_handler("duration-field")
10741078
.with_description(
10751079
"The name of the duration field in the log message pattern")

src/root-config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@
147147
},
148148
"external-editor": {
149149
"impls": {
150+
"IntelliJ": {
151+
"config-dir": ".idea",
152+
"prefers": "^.*(?:\\.java|\\.kt)$",
153+
"test": "command -v idea",
154+
"command": "idea --line ${LINE} --column ${COL} \"$FILE_PATH\""
155+
},
150156
"CLion": {
151157
"config-dir": ".idea",
152158
"test": "command -v clion",

0 commit comments

Comments
 (0)