[glog] some tweaks to the glog change

Some changes to the glog_log sql table:

  * Removed the 'glog_level' field since the standard one should be able to
    handle everything now.
  * Changed the 'file' column to 'src_file' and added a 'src_line' column.
  * Added the sample glog log content to the test directory.
pull/69/head
Timothy Stack 11 years ago
parent f3a85327ab
commit b04e6bfc78

@ -425,6 +425,7 @@ public:
for (iter = bucket.begin(); iter != bucket.end(); iter++) {
total += (int)iter->second;
switch (iter->first) {
case logline::LEVEL_FATAL:
case logline::LEVEL_ERROR:
case logline::LEVEL_CRITICAL:
errors += (int)iter->second;
@ -2085,6 +2086,8 @@ static void looper(void)
hist_source &hs = lnav_data.ld_hist_source;
lnav_data.ld_hist_zoom = 2;
hs.set_role_for_type(bucket_type_t(logline::LEVEL_FATAL),
view_colors::VCR_ERROR);
hs.set_role_for_type(bucket_type_t(logline::LEVEL_CRITICAL),
view_colors::VCR_ERROR);
hs.set_role_for_type(bucket_type_t(logline::LEVEL_ERROR),
@ -2368,32 +2371,32 @@ public:
glog_log_table()
: log_vtab_impl("glog_log"),
slt_regex(
"\\s*([IWECF])([0-9]*) ([0-9:.]*)" // level, date
"\\s*(?:[IWECF])([0-9]*) ([0-9:.]*)" // level, date
"\\s*([0-9]*)" // thread
"\\s*(.*:[0-9]*)\\]" // filename:number
"\\s*(.*):(\\d*)\\]" // filename:number
"\\s*(.*)"
) {
};
void get_columns(vector<vtab_column> &cols) {
cols.push_back(vtab_column("glog_level", "text"));
cols.push_back(vtab_column("timestamp", "text"));
cols.push_back(vtab_column("thread", "text"));
cols.push_back(vtab_column("file", "text"));
cols.push_back(vtab_column("src_file", "text"));
cols.push_back(vtab_column("src_line", "int"));
cols.push_back(vtab_column("message", "text"));
};
void extract(const std::string &line,
int column,
sqlite3_context *ctx) {
string level, date, time, thread, file, message = "0";
string date, time, thread, file, src_line, message = "0";
if (!this->slt_regex.FullMatch(line,
&level,
&date,
&time,
&thread,
&file,
&src_line,
&message
)) {
fprintf(stderr, "bad match! %s\n", line.c_str());
@ -2404,12 +2407,6 @@ public:
char buf[128];
switch (column) {
case 0:
sqlite3_result_text(ctx,
level.c_str(),
level.length(),
SQLITE_TRANSIENT);
break;
case 1:
localtime_r(&now, &log_time); // need year data
strptime(date.data(), "%m%d", &log_time);
strftime(buf, sizeof(buf), "%Y-%m-%d", &log_time);
@ -2424,18 +2421,24 @@ public:
timestamp.str().length(),
SQLITE_TRANSIENT);
break;
case 2:
case 1:
sqlite3_result_text(ctx,
thread.c_str(),
thread.length(),
SQLITE_TRANSIENT);
break;
case 3:
case 2:
sqlite3_result_text(ctx,
file.c_str(),
file.length(),
SQLITE_TRANSIENT);
break;
case 3:
sqlite3_result_text(ctx,
src_line.c_str(),
src_line.length(),
SQLITE_TRANSIENT);
break;
case 4:
sqlite3_result_text(ctx,
message.c_str(),

@ -98,7 +98,8 @@ const char *logline::level_names[LEVEL__MAX] = {
"info",
"warning",
"error",
"critical"
"critical",
"fatal",
};
logline::level_t logline::string2level(const char *levelstr)
@ -126,6 +127,9 @@ logline::level_t logline::string2level(const char *levelstr)
else if (strcasestr(levelstr, "CRITICAL")) {
retval = logline::LEVEL_CRITICAL;
}
else if (strcasestr(levelstr, "FATAL")) {
retval = logline::LEVEL_FATAL;
}
return retval;
}

@ -58,6 +58,7 @@ public:
LEVEL_WARNING,
LEVEL_ERROR,
LEVEL_CRITICAL,
LEVEL_FATAL,
LEVEL__MAX,

@ -402,7 +402,7 @@ class glog_log_format : public log_format {
ll = logline::LEVEL_CRITICAL;
break;
case 'F': // fatal
ll = logline::LEVEL_CRITICAL;
ll = logline::LEVEL_FATAL;
break;
}
log_gmt = tm2sec(&log_time);

@ -266,6 +266,7 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv,
int attrs = 0;
switch (this->lss_token_line->get_level() & ~logline::LEVEL__FLAGS) {
case logline::LEVEL_FATAL:
case logline::LEVEL_CRITICAL:
case logline::LEVEL_ERROR:
attrs = vc.attrs_for_role(view_colors::VCR_ERROR);
@ -498,6 +499,7 @@ void logfile_sub_source::text_update_marks(vis_bookmarks &bm)
bm[&BM_WARNINGS].insert_once(vl);
break;
case logline::LEVEL_FATAL:
case logline::LEVEL_ERROR:
case logline::LEVEL_CRITICAL:
bm[&BM_ERRORS].insert_once(vl);

@ -161,6 +161,7 @@ dist_noinst_DATA = \
logfile_access_log.0 \
logfile_empty.0 \
logfile_generic.0 \
logfile_glog.0 \
logfile_strace_log.0 \
logfile_syslog.0 \
logfile_syslog.1 \

@ -700,6 +700,7 @@ dist_noinst_DATA = \
logfile_access_log.0 \
logfile_empty.0 \
logfile_generic.0 \
logfile_glog.0 \
logfile_strace_log.0 \
logfile_syslog.0 \
logfile_syslog.1 \

@ -0,0 +1,7 @@
E0517 15:04:22.619632 1952452992 logging_unittest.cc:253] Log every 3, iteration 19
I0517 15:04:22.619642 1952452992 logging_unittest.cc:259] Log if every 1, iteration 19
I0517 15:04:22.619740 1952452992 logging_unittest.cc:259] Log if every 1, iteration 20
W0517 15:04:22.619751 1952452992 logging_unittest.cc:263] log_if this
I0517 15:04:22.619760 1952452992 logging_unittest.cc:267] array
I0517 15:04:22.619768 1952452992 logging_unittest.cc:269] const array
E0517 15:04:22.619776 1952452992 logging_unittest.cc:271] foo 1000 0000001000 3e8

@ -124,3 +124,27 @@ run_test ./drive_logfile -v -f generic_log ${srcdir}/logfile_generic.0
check_output "generic_log level interpreted incorrectly?" <<EOF
0x02
EOF
run_test ./drive_logfile -t -f glog_log ${srcdir}/logfile_glog.0
check_output "glog_log timestamp interpreted incorrectly?" <<EOF
May 17 15:04:22 2007 -- 619
May 17 15:04:22 2007 -- 619
May 17 15:04:22 2007 -- 619
May 17 15:04:22 2007 -- 619
May 17 15:04:22 2007 -- 619
May 17 15:04:22 2007 -- 619
May 17 15:04:22 2007 -- 619
EOF
run_test ./drive_logfile -v -f glog_log ${srcdir}/logfile_glog.0
check_output "glog_log level interpreted incorrectly?" <<EOF
0x05
0x03
0x03
0x04
0x03
0x03
0x05
EOF

Loading…
Cancel
Save