[sql] log table nits

pull/69/head
Timothy Stack 11 years ago
parent c28b9f1316
commit 3ee6dbf824

@ -68,7 +68,8 @@
"identifier" : true
},
"sc_status" : {
"kind" : "integer"
"kind" : "integer",
"foreign-key" : true
},
"sc_bytes" : {
"kind" : "integer"

@ -246,6 +246,7 @@ public:
}
size_t total_count = (1 +
1 +
this->fos_line_values.size() +
1 +
this->fos_parser->dp_pairs.size());
@ -2945,54 +2946,6 @@ static void looper(void)
}
}
class access_log_table : public log_vtab_impl {
public:
access_log_table()
: log_vtab_impl("access_log") {};
void get_columns(vector<vtab_column> &cols)
{
cols.push_back(vtab_column("c_ip", SQLITE3_TEXT, "ipaddress"));
cols.push_back(vtab_column("cs_username", SQLITE3_TEXT));
cols.push_back(vtab_column("cs_method", SQLITE3_TEXT));
cols.push_back(vtab_column("cs_uri_stem", SQLITE3_TEXT));
cols.push_back(vtab_column("cs_uri_query", SQLITE3_TEXT));
cols.push_back(vtab_column("cs_version", SQLITE3_TEXT));
cols.push_back(vtab_column("sc_status", SQLITE_INTEGER));
cols.push_back(vtab_column("sc_bytes", SQLITE_INTEGER));
cols.push_back(vtab_column("cs_referer", SQLITE3_TEXT));
cols.push_back(vtab_column("cs_user_agent", SQLITE3_TEXT));
};
void get_foreign_keys(vector<string> &keys_inout)
{
this->log_vtab_impl::get_foreign_keys(keys_inout);
keys_inout.push_back("sc_status");
};
};
class syslog_log_table : public log_vtab_impl {
public:
syslog_log_table()
: log_vtab_impl("syslog_log") {};
void get_columns(vector<vtab_column> &cols)
{
cols.push_back(vtab_column("log_hostname", SQLITE3_TEXT));
cols.push_back(vtab_column("log_pid", SQLITE_INTEGER));
};
void get_foreign_keys(vector<string> &keys_inout)
{
this->log_vtab_impl::get_foreign_keys(keys_inout);
keys_inout.push_back("log_pid");
};
};
class glog_log_table : public log_vtab_impl {
public:
@ -3279,7 +3232,7 @@ static void setup_highlights(textview_curses::highlight_map_t &hm)
hm["$ip"] = textview_curses::
highlighter(xpcre_compile("\\d+\\.\\d+\\.\\d+\\.\\d+"));
hm["$comment"] = textview_curses::highlighter(xpcre_compile(
"(?<!:)//.*|/\\*.*\\*/|#.*|dnl.*"), false, view_colors::VCR_COMMENT);
"(?<!:)//.*|/\\*.*\\*/|^#.*|\\s+#.*|dnl.*"), false, view_colors::VCR_COMMENT);
hm["$javadoc"] = textview_curses::highlighter(xpcre_compile(
"@(?:author|deprecated|exception|file|param|return|see|since|throws|version)"));
hm["$var"] = textview_curses::highlighter(xpcre_compile(
@ -3376,9 +3329,7 @@ int main(int argc, char *argv[])
}
}
lnav_data.ld_vtab_manager->register_vtab(new syslog_log_table());
lnav_data.ld_vtab_manager->register_vtab(new log_vtab_impl("generic_log"));
lnav_data.ld_vtab_manager->register_vtab(new access_log_table());
lnav_data.ld_vtab_manager->register_vtab(new glog_log_table());
lnav_data.ld_vtab_manager->register_vtab(new strace_log_table());

@ -50,7 +50,12 @@ public:
log_data_table(content_line_t template_line,
std::string table_name = "logline")
: log_vtab_impl(table_name),
ldt_template_line(template_line) {};
ldt_template_line(template_line) {
logfile *lf = lnav_data.ld_log_source.find(template_line);
log_format *format = lf->get_format();
this->ldt_format_impl = lnav_data.ld_vtab_manager->lookup_impl(format->get_name());
};
void get_columns(std::vector<vtab_column> &cols)
{
@ -62,8 +67,12 @@ public:
struct line_range body;
string_attrs_t sa;
std::vector<logline_value> line_values;
log_format *format = lf->get_format();
lf->get_format()->annotate(val, sa, line_values);
if (this->ldt_format_impl != NULL) {
this->ldt_format_impl->get_columns(cols);
}
format->annotate(val, sa, line_values);
body = find_string_attr_range(sa, "body");
if (body.lr_end == -1 || body.length() == 0) {
this->ldt_schema_id.clear();
@ -165,6 +174,7 @@ public:
const std::string &line,
std::vector<logline_value> &values)
{
this->ldt_format_impl->extract(lf, line, values);
for (data_parser::element_list_t::iterator pair_iter =
this->ldt_pairs.begin();
pair_iter != this->ldt_pairs.end();
@ -195,5 +205,6 @@ private:
data_parser::schema_id_t ldt_schema_id;
std::string ldt_current_line;
data_parser::element_list_t ldt_pairs;
log_vtab_impl *ldt_format_impl;
};
#endif

@ -425,6 +425,21 @@ public:
}
};
void get_foreign_keys(std::vector<std::string> &keys_inout)
{
std::map<std::string, external_log_format::value_def>::const_iterator iter;
log_vtab_impl::get_foreign_keys(keys_inout);
for (iter = this->elt_format.elf_value_defs.begin();
iter != this->elt_format.elf_value_defs.end();
++iter) {
if (iter->second.vd_foreign_key) {
keys_inout.push_back(iter->first);
}
}
};
const external_log_format &elt_format;
};

@ -451,6 +451,7 @@ public:
logline_value::kind_t vd_kind;
std::string vd_collate;
bool vd_identifier;
bool vd_foreign_key;
bool operator<(const value_def &rhs) const {
return this->vd_index < rhs.vd_index;

@ -113,13 +113,17 @@ static int read_value_def(void *ctx, const unsigned char *str, size_t len)
return 1;
}
static int read_value_ident(void *ctx, int val)
static int read_value_bool(void *ctx, int val)
{
yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx;
external_log_format *elf = ensure_format(ypc->get_path_fragment(0));
string value_name = ypc->get_path_fragment(2);
string key_name = ypc->get_path_fragment(3);
elf->elf_value_defs[value_name].vd_identifier = val;
if (key_name == "identifier")
elf->elf_value_defs[value_name].vd_identifier = val;
else if (key_name == "foreign-key")
elf->elf_value_defs[value_name].vd_foreign_key = val;
return 1;
}
@ -152,7 +156,7 @@ static struct json_path_handler format_handlers[] = {
"(trace|debug|info|warning|error|critical|fatal)",
read_levels),
json_path_handler("/\\w+/value/\\w+/(kind)", read_value_def),
json_path_handler("/\\w+/value/\\w+/identifier", read_value_ident),
json_path_handler("/\\w+/value/\\w+/(identifier|foreign-key)", read_value_bool),
json_path_handler("/\\w+/sample#/line", read_sample_line),
json_path_handler()

Loading…
Cancel
Save