Skip to content

Commit c44e3be

Browse files
authored
Merge branch 'tstack:master' into log-formats
2 parents ce88dce + 2f0fb22 commit c44e3be

15 files changed

+97
-31
lines changed

docs/source/faq.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,12 @@ Q: Why isn't a file being displayed?
8383

8484
:Details: If a file being monitored by lnav does not match a known log file
8585
format, it is treated as plaintext and will be displayed in the TEXT view.
86+
87+
Q: How can I search for an exact word?
88+
--------------------------------------
89+
90+
:Solution: Surround the word to search for with :code:`\b`.
91+
92+
:Details: The :code:`\b` means "word break" and matches a position where a
93+
"word" ends. That is, right before a space character, punctuation, etc,
94+
or at EOL.

src/base/time_util.cc

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,26 @@ get_posix_zone(const char* name)
104104
}
105105
}
106106

107-
static const date::time_zone*
107+
static std::optional<const date::time_zone*>
108108
get_date_zone(const char* name)
109109
{
110110
if (name == nullptr) {
111-
return date::current_zone();
111+
try {
112+
return date::current_zone();
113+
} catch (const std::runtime_error& e) {
114+
return std::nullopt;
115+
}
112116
}
113117

114118
try {
115119
return date::locate_zone(name);
116120
} catch (const std::runtime_error& e) {
117121
log_error("invalid TZ value: %s -- %s", name, e.what());
118-
return date::current_zone();
122+
try {
123+
return date::current_zone();
124+
} catch (const std::runtime_error& e) {
125+
return std::nullopt;
126+
}
119127
}
120128
}
121129

@@ -124,57 +132,82 @@ to_sys_time(date::local_seconds secs)
124132
{
125133
static const auto* TZ = getenv("TZ");
126134
static const auto TZ_POSIX_ZONE = get_posix_zone(TZ);
127-
static const auto* TZ_DATE_ZONE = get_date_zone(TZ);
128-
129135
if (TZ_POSIX_ZONE) {
130136
return TZ_POSIX_ZONE.value().to_sys(secs);
131137
}
132138

133-
auto inf = TZ_DATE_ZONE->get_info(secs);
139+
static const auto TZ_DATE_ZONE = get_date_zone(TZ);
134140

135-
return TZ_DATE_ZONE->to_sys(secs);
141+
if (TZ_DATE_ZONE) {
142+
auto inf = TZ_DATE_ZONE.value()->get_info(secs);
143+
144+
return TZ_DATE_ZONE.value()->to_sys(secs);
145+
}
146+
147+
static const auto TZ_POSIX_UTC = get_posix_zone("UTC0");
148+
149+
return TZ_POSIX_UTC.value().to_sys(secs);
136150
}
137151

138152
date::local_seconds
139153
to_local_time(date::sys_seconds secs)
140154
{
141155
static const auto* TZ = getenv("TZ");
142156
static const auto TZ_POSIX_ZONE = get_posix_zone(TZ);
143-
static const auto* TZ_DATE_ZONE = get_date_zone(TZ);
144157

145158
if (TZ_POSIX_ZONE) {
146159
return TZ_POSIX_ZONE.value().to_local(secs);
147160
}
148161

149-
return TZ_DATE_ZONE->to_local(secs);
162+
static const auto TZ_DATE_ZONE = get_date_zone(TZ);
163+
164+
if (TZ_DATE_ZONE) {
165+
return TZ_DATE_ZONE.value()->to_local(secs);
166+
}
167+
168+
static const auto TZ_POSIX_UTC = get_posix_zone("UTC0");
169+
170+
return TZ_POSIX_UTC.value().to_local(secs);
150171
}
151172

152173
date::sys_info
153174
sys_time_to_info(date::sys_seconds secs)
154175
{
155176
static const auto* TZ = getenv("TZ");
156177
static const auto TZ_POSIX_ZONE = get_posix_zone(TZ);
157-
static const auto* TZ_DATE_ZONE = get_date_zone(TZ);
158178

159179
if (TZ_POSIX_ZONE) {
160180
return TZ_POSIX_ZONE.value().get_info(secs);
161181
}
162182

163-
return TZ_DATE_ZONE->get_info(secs);
183+
static const auto TZ_DATE_ZONE = get_date_zone(TZ);
184+
if (TZ_DATE_ZONE) {
185+
return TZ_DATE_ZONE.value()->get_info(secs);
186+
}
187+
188+
static const auto TZ_POSIX_UTC = get_posix_zone("UTC0");
189+
190+
return TZ_POSIX_UTC.value().get_info(secs);
164191
}
165192

166193
date::local_info
167194
local_time_to_info(date::local_seconds secs)
168195
{
169196
static const auto* TZ = getenv("TZ");
170197
static const auto TZ_POSIX_ZONE = get_posix_zone(TZ);
171-
static const auto* TZ_DATE_ZONE = get_date_zone(TZ);
172198

173199
if (TZ_POSIX_ZONE) {
174200
return TZ_POSIX_ZONE.value().get_info(secs);
175201
}
176202

177-
return TZ_DATE_ZONE->get_info(secs);
203+
static const auto TZ_DATE_ZONE = get_date_zone(TZ);
204+
if (TZ_DATE_ZONE) {
205+
return TZ_DATE_ZONE.value()->get_info(secs);
206+
}
207+
208+
static const auto TZ_POSIX_UTC = get_posix_zone("UTC0");
209+
210+
return TZ_POSIX_UTC.value().get_info(secs);
178211
}
179212

180213
} // namespace lnav

src/formats/java_log.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@
3939
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}( |T)\\d{2}:\\d{2}:\\d{2}(,|\\.)\\d{3}(?:Z|[-+]\\d{2}:?\\d{2})?)\\s+\\[(?<thread>[^\\]]+)\\]\\s+(?<level>ERROR|WARN|INFO|DEBUG|TRACE)\\s+opId=(?<opid>\\S*)\\s+(?<class>\\S+)\\s+-\\s+(?<body>.*)$"
4040
},
4141
"level-thread-class": {
42-
"pattern": "(?<timestamp>\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}[,\\.]\\d{3}) (?<level>\\w+)\\s+\\[(?<thread>[^\\]]+)\\] (?<class>[^:]+): (?<body>.*)"
42+
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}[,\\.]\\d{1,3}) (?<level>\\w+)\\s+\\[(?<thread>[^\\]]+)\\] (?<class>[^:]+): (?<body>.*)"
4343
},
4444
"level-class-src": {
45-
"pattern": "(?<timestamp>\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}[,\\.]\\d{3}) (?<level>\\w+)\\s+(?<class>[\\.\\w]+) \\((?<srcfile>[^:]+):(?<function>[^(]+)\\((?<srcline>\\d+)\\)\\) - (?<body>.*)"
45+
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}[,\\.]\\d{1,3}) (?<level>\\w+)\\s+(?<class>[\\.\\w]+) \\((?<srcfile>[^:]+):(?<function>[^(]+)\\((?<srcline>\\d+)\\)\\) - (?<body>.*)"
46+
},
47+
"repeated": {
48+
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}[,\\.]\\d{1,3}) \\^\\^\\^ \\d+ similar messages? omitted \\^\\^\\^$"
4649
}
4750
},
4851
"level-field": "level",
@@ -172,6 +175,9 @@
172175
},
173176
{
174177
"line": "2024-04-23 09:17:33,457 INFO namenode.NameNode (LogAdapter.java:info(51)) - registered UNIX signal handlers for [TERM, HUP, INT]"
178+
},
179+
{
180+
"line": "2024-07-18 14:06:40.554 ^^^ 1 similar message omitted ^^^"
175181
}
176182
]
177183
}

src/log_format.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ external_log_format::scan(logfile& lf,
15231523
opid = opid_cap->hash();
15241524
}
15251525

1526-
if (mod_cap) {
1526+
if (mod_cap && body_cap) {
15271527
intern_string_t mod_name = intern_string::lookup(mod_cap.value());
15281528
auto mod_iter = MODULE_FORMATS.find(mod_name);
15291529

@@ -1539,7 +1539,7 @@ external_log_format::scan(logfile& lf,
15391539
mod_iter->second.mf_mod_format);
15401540

15411541
if (mod_elf) {
1542-
static thread_local auto mod_md
1542+
thread_local auto mod_md
15431543
= lnav::pcre2pp::match_data::unitialized();
15441544

15451545
shared_buffer_ref body_ref;

src/logfile.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,14 @@ logfile::open(std::filesystem::path filename,
182182
if (!phdr.h_timezone.empty()) {
183183
log_info("setting default time zone from piper header: %s",
184184
phdr.h_timezone.c_str());
185-
fo.fo_default_zone.pp_value
186-
= date::locate_zone(phdr.h_timezone);
185+
try {
186+
fo.fo_default_zone.pp_value
187+
= date::locate_zone(phdr.h_timezone);
188+
} catch (const std::runtime_error& e) {
189+
log_error("unable to get tz from piper header %s -- %s",
190+
phdr.h_timezone.c_str(),
191+
e.what());
192+
}
187193
}
188194
if (!fo.empty()) {
189195
safe::WriteAccess<lnav::safe_file_options_hier>

src/readline_possibilities.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,12 @@ add_tz_possibilities(ln_mode_t context)
560560
auto* rc = lnav_data.ld_rl_view;
561561

562562
rc->clear_possibilities(context, "timezone");
563-
for (const auto& tz : date::get_tzdb().zones) {
564-
rc->add_possibility(context, "timezone", tz.name());
563+
try {
564+
for (const auto& tz : date::get_tzdb().zones) {
565+
rc->add_possibility(context, "timezone", tz.name());
566+
}
567+
} catch (const std::runtime_error& e) {
568+
log_error("unable to get tzdb -- %s", e.what());
565569
}
566570

567571
{

src/time_formats.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ TIME_FORMATS = \
2525
"%y-%m-%dT%H:%M:%S.%f%z" \
2626
"%Y-%m-%dT%H:%M:%S.%L%z" \
2727
"%y-%m-%dT%H:%M:%S.%L%z" \
28+
"%Y-%m-%dT%H:%M:%S.%L%Z" \
29+
"%y-%m-%dT%H:%M:%S.%L%Z" \
2830
"%Y-%m-%dT%H:%M:%S%z" \
2931
"%Y-%m-%dT%H:%M:%S%z" \
3032
"%Y-%m-%dT%H:%M:%S" \

src/vtab_module.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ struct vtab_module : public vtab_module_base {
582582
struct vtab {
583583
explicit vtab(sqlite3* db, T& impl) : v_db(db), v_impl(impl) {}
584584

585-
explicit operator sqlite3_vtab*() { return &this->base; }
585+
explicit operator sqlite3_vtab*() { return &this->v_base; }
586586

587587
sqlite3_vtab v_base{};
588588
sqlite3* v_db;

test/expected/expected.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,8 @@ EXPECTED_FILES = \
11381138
$(srcdir)/%reldir%/test_sql_time_func.sh_123c85ff1178743f5cb78efeaf98b637bcbe55ff.out \
11391139
$(srcdir)/%reldir%/test_sql_time_func.sh_14737ee9597b7d22519d23fbe34c0eb7d6c09ff2.err \
11401140
$(srcdir)/%reldir%/test_sql_time_func.sh_14737ee9597b7d22519d23fbe34c0eb7d6c09ff2.out \
1141+
$(srcdir)/%reldir%/test_sql_time_func.sh_1804a2824c5e7dee903ef7500a3b60a123b7de01.err \
1142+
$(srcdir)/%reldir%/test_sql_time_func.sh_1804a2824c5e7dee903ef7500a3b60a123b7de01.out \
11411143
$(srcdir)/%reldir%/test_sql_time_func.sh_1fbeb1ba69a95284eb1d4d052f5068ede7968704.err \
11421144
$(srcdir)/%reldir%/test_sql_time_func.sh_1fbeb1ba69a95284eb1d4d052f5068ede7968704.out \
11431145
$(srcdir)/%reldir%/test_sql_time_func.sh_20477acc218c96f1385dc97e4d28c80a05c93709.err \
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
✘ error: invalid timestamp: 2022-03-02T10:20:30+
2+
reason: the leading part of the timestamp was matched, however, the trailing text “+” was not
3+
--> command-option:1
4+
| ;SELECT timezone('UTC', '2022-03-02T10:20:30+')
5+
= note: input matched time format “%Y-%m-%dT%H:%M:%S”
6+
= note: 2022-03-02T10:20:30+
7+
^ unrecognized input
8+
= help: fix the timestamp or remove the trailing text

test/expected/test_sql_time_func.sh_1804a2824c5e7dee903ef7500a3b60a123b7de01.out

Whitespace-only changes.
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
✘ error: invalid timestamp: 2022-03-02T10:20:30.400bad
2-
reason: the leading part of the timestamp was matched, however, the trailing text “bad” was not
3-
--> command-option:1
4-
| ;SELECT timezone('UTC', '2022-03-02T10:20:30.400bad')
5-
= note: input matched time format “%Y-%m-%dT%H:%M:%S”
6-
= note: 2022-03-02T10:20:30.400bad
7-
^-^ unrecognized input
8-
= help: fix the timestamp or remove the trailing text
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
timezone('UTC', '2022-03-02T10:20:30.400bad')
2+
2022-03-02T10:20:30.400000+0000

test/logfile_invalid_tz.0

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2015-04-24T21:08:10.313913FOO err rbd [22968]lotuscreds:ERROR:Could not retrieve lotus account information from db
2+
2015-04-24T21:08:58.430632FOO err rbd [24206]networkutil:ERROR:The configured address sg01-1-vc1.oc.vmware.com was invalid

test/test_sql_time_func.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ run_cap_test ./drive_sql "SELECT timezone('UTC', '2022-03-02T10:20:30.400-0700')
8282

8383
run_cap_test ${lnav_test} -nN -c ";SELECT timezone('bad-zone', '2022-03-02T10:20:30.400-0700')"
8484

85-
run_cap_test ${lnav_test} -nN -c ";SELECT timezone('UTC', '2022-03-02T10:20:30.400bad')"
85+
run_cap_test ${lnav_test} -nN -c ";SELECT timezone('UTC', '2022-03-02T10:20:30+')"

0 commit comments

Comments
 (0)