mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
[json] record the type of json data in json_ptr_walk
This commit is contained in:
parent
e987a5164f
commit
187d62334f
@ -431,7 +431,9 @@ int sql_callback(sqlite3_stmt *stmt)
|
||||
else {
|
||||
value_len = strlen(value);
|
||||
}
|
||||
if (value != NULL && dls.dls_headers[lpc] == "log_line") {
|
||||
if (value != NULL &&
|
||||
(dls.dls_headers[lpc] == "log_line" ||
|
||||
dls.dls_headers[lpc] == "min(log_line)")) {
|
||||
int line_number = -1;
|
||||
|
||||
if (sscanf(value, "%d", &line_number) == 1) {
|
||||
@ -451,12 +453,13 @@ int sql_callback(sqlite3_stmt *stmt)
|
||||
|
||||
if (jpw.parse(value, value_len) == yajl_status_ok &&
|
||||
jpw.complete_parse() == yajl_status_ok) {
|
||||
for (json_ptr_walk::pair_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
iter != jpw.jpw_values.end();
|
||||
++iter) {
|
||||
if (sscanf(iter->second.c_str(), "%lf", &num_value) == 1) {
|
||||
chart.add_value(iter->first, num_value);
|
||||
chart.with_attrs_for_ident(iter->first, vc.attrs_for_ident(iter->first));
|
||||
if (iter->wt_type == yajl_t_number &&
|
||||
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
|
||||
chart.add_value(iter->wt_ptr, num_value);
|
||||
chart.with_attrs_for_ident(iter->wt_ptr, vc.attrs_for_ident(iter->wt_ptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,12 +133,14 @@ public:
|
||||
|
||||
if (jpw.parse(row_value, row_len) == yajl_status_ok &&
|
||||
jpw.complete_parse() == yajl_status_ok) {
|
||||
for (json_ptr_walk::pair_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
iter != jpw.jpw_values.end();
|
||||
++iter) {
|
||||
double num_value;
|
||||
if (sscanf(iter->second.c_str(), "%lf", &num_value) == 1) {
|
||||
this->dls_chart.chart_attrs_for_value(tc, left, iter->first, num_value, sa);
|
||||
|
||||
if (iter->wt_type == yajl_t_number &&
|
||||
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
|
||||
this->dls_chart.chart_attrs_for_value(tc, left, iter->wt_ptr, num_value, sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -275,42 +277,44 @@ public:
|
||||
chart.with_stacking_enabled(false)
|
||||
.with_margins(3, 0);
|
||||
|
||||
for (json_ptr_walk::pair_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
iter != jpw.jpw_values.end();
|
||||
++iter) {
|
||||
this->dos_lines.push_back(" " + iter->first + " = " + iter->second);
|
||||
this->dos_lines.push_back(" " + iter->wt_ptr + " = " + iter->wt_value);
|
||||
|
||||
string_attrs_t &sa = this->dos_lines.back().get_attrs();
|
||||
struct line_range lr(1, 2);
|
||||
|
||||
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_LTEE));
|
||||
lr.lr_start = 3 + iter->first.size() + 3;
|
||||
lr.lr_start = 3 + iter->wt_ptr.size() + 3;
|
||||
lr.lr_end = -1;
|
||||
sa.push_back(string_attr(lr, &view_curses::VC_STYLE, A_BOLD));
|
||||
|
||||
double num_value = 0.0;
|
||||
|
||||
if (sscanf(iter->second.c_str(), "%lf", &num_value) == 1) {
|
||||
int attrs = vc.attrs_for_ident(iter->first);
|
||||
if (iter->wt_type == yajl_t_number &&
|
||||
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
|
||||
int attrs = vc.attrs_for_ident(iter->wt_ptr);
|
||||
|
||||
chart.add_value(iter->first, num_value);
|
||||
chart.with_attrs_for_ident(iter->first, attrs);
|
||||
chart.add_value(iter->wt_ptr, num_value);
|
||||
chart.with_attrs_for_ident(iter->wt_ptr, attrs);
|
||||
}
|
||||
|
||||
retval += 1;
|
||||
}
|
||||
|
||||
int curr_line = start_line;
|
||||
for (json_ptr_walk::pair_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
iter != jpw.jpw_values.end();
|
||||
++iter, curr_line++) {
|
||||
double num_value = 0.0;
|
||||
|
||||
if (sscanf(iter->second.c_str(), "%lf", &num_value) == 1) {
|
||||
if (iter->wt_type == yajl_t_number &&
|
||||
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
|
||||
string_attrs_t &sa = this->dos_lines[curr_line].get_attrs();
|
||||
int left = 3;
|
||||
|
||||
chart.chart_attrs_for_value(lv, left, iter->first, num_value, sa);
|
||||
chart.chart_attrs_for_value(lv, left, iter->wt_ptr, num_value, sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ size_t field_overlay_source::list_overlay_count(const listview_curses &lv)
|
||||
this->add_key_line_attrs(this->fos_known_key_size);
|
||||
}
|
||||
|
||||
std::map<const intern_string_t, json_ptr_walk::pair_list_t>::iterator json_iter;
|
||||
std::map<const intern_string_t, json_ptr_walk::walk_list_t>::iterator json_iter;
|
||||
|
||||
if (!this->fos_log_helper.ldh_json_pairs.empty()) {
|
||||
this->fos_lines.push_back(" JSON fields:");
|
||||
@ -155,12 +155,12 @@ size_t field_overlay_source::list_overlay_count(const listview_curses &lv)
|
||||
for (json_iter = this->fos_log_helper.ldh_json_pairs.begin();
|
||||
json_iter != this->fos_log_helper.ldh_json_pairs.end();
|
||||
++json_iter) {
|
||||
json_ptr_walk::pair_list_t &jpairs = json_iter->second;
|
||||
json_ptr_walk::walk_list_t &jpairs = json_iter->second;
|
||||
|
||||
for (size_t lpc = 0; lpc < jpairs.size(); lpc++) {
|
||||
this->fos_lines.push_back(" " +
|
||||
this->fos_log_helper.format_json_getter(json_iter->first, lpc) + " = " +
|
||||
jpairs[lpc].second);
|
||||
jpairs[lpc].wt_value);
|
||||
this->add_key_line_attrs(0);
|
||||
}
|
||||
}
|
||||
|
14
src/help.txt
14
src/help.txt
@ -342,10 +342,16 @@ through the file.
|
||||
will cycle through the columns until they are all graphed
|
||||
again.
|
||||
|
||||
p Enable or disable the display of the fields that the
|
||||
log message parser knows about or has discovered.
|
||||
This overlay is temporarily enabled when the semicolon
|
||||
key (;) is pressed so that it is easier to write queries.
|
||||
p In the log view: enable or disable the display of the
|
||||
fields that the log message parser knows about or has
|
||||
discovered. This overlay is temporarily enabled when the
|
||||
semicolon key (;) is pressed so that it is easier to write
|
||||
queries.
|
||||
|
||||
In the DB view: enable or disable the display of values
|
||||
in columns containing JSON-encoded values in the top row.
|
||||
The overlay will display the JSON-Pointer reference and
|
||||
value for all fields in the JSON data.
|
||||
|
||||
X Close the current text file or log file.
|
||||
|
||||
|
@ -39,7 +39,8 @@ static int handle_null(void *ctx)
|
||||
{
|
||||
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
|
||||
|
||||
jpw->jpw_values.push_back(make_pair(jpw->current_ptr(), "null"));
|
||||
jpw->jpw_values.push_back(
|
||||
json_ptr_walk::walk_triple(jpw->current_ptr(), yajl_t_null, "null"));
|
||||
jpw->inc_array_index();
|
||||
|
||||
return 1;
|
||||
@ -49,7 +50,10 @@ static int handle_boolean(void *ctx, int boolVal)
|
||||
{
|
||||
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
|
||||
|
||||
jpw->jpw_values.push_back(make_pair(jpw->current_ptr(), boolVal ? "true" : "false"));
|
||||
jpw->jpw_values.push_back(
|
||||
json_ptr_walk::walk_triple(jpw->current_ptr(),
|
||||
boolVal ? yajl_t_true : yajl_t_false,
|
||||
boolVal ? "true" : "false"));
|
||||
jpw->inc_array_index();
|
||||
|
||||
return 1;
|
||||
@ -59,7 +63,10 @@ static int handle_number(void *ctx, const char *numberVal, size_t numberLen)
|
||||
{
|
||||
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
|
||||
|
||||
jpw->jpw_values.push_back(make_pair(jpw->current_ptr(), string(numberVal, numberLen)));
|
||||
jpw->jpw_values.push_back(
|
||||
json_ptr_walk::walk_triple(jpw->current_ptr(),
|
||||
yajl_t_number,
|
||||
string(numberVal, numberLen)));
|
||||
jpw->inc_array_index();
|
||||
|
||||
return 1;
|
||||
@ -81,7 +88,8 @@ static int handle_string(void *ctx, const unsigned char * stringVal, size_t len)
|
||||
gen = yajl_gen_alloc(NULL);
|
||||
yajl_gen_config(gen.in(), yajl_gen_print_callback, appender, &str);
|
||||
yajl_gen_string(gen.in(), stringVal, len);
|
||||
jpw->jpw_values.push_back(make_pair(jpw->current_ptr(), str));
|
||||
jpw->jpw_values.push_back(
|
||||
json_ptr_walk::walk_triple(jpw->current_ptr(), yajl_t_string, str));
|
||||
jpw->inc_array_index();
|
||||
|
||||
return 1;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "yajlpp.hh"
|
||||
#include "yajl/api/yajl_tree.h"
|
||||
#include "lnav_log.hh"
|
||||
|
||||
class json_ptr_walk {
|
||||
@ -113,11 +114,22 @@ public:
|
||||
return retval;
|
||||
};
|
||||
|
||||
typedef std::vector<std::pair<std::string, std::string> > pair_list_t;
|
||||
struct walk_triple {
|
||||
walk_triple(std::string ptr, yajl_type type, std::string value)
|
||||
: wt_ptr(ptr), wt_type(type), wt_value(value) {
|
||||
|
||||
};
|
||||
|
||||
std::string wt_ptr;
|
||||
yajl_type wt_type;
|
||||
std::string wt_value;
|
||||
};
|
||||
|
||||
typedef std::vector<walk_triple> walk_list_t;
|
||||
|
||||
auto_mem<yajl_handle_t> jpw_handle;
|
||||
std::string jpw_error_msg;
|
||||
pair_list_t jpw_values;
|
||||
walk_list_t jpw_values;
|
||||
std::vector<std::string> jpw_keys;
|
||||
std::vector<int32_t> jpw_array_indexes;
|
||||
size_t jpw_max_ptr_len;
|
||||
|
@ -271,10 +271,10 @@ bool setup_logline_table()
|
||||
|
||||
ldh.parse_line(cl);
|
||||
|
||||
std::map<const intern_string_t, json_ptr_walk::pair_list_t>::const_iterator pair_iter;
|
||||
std::map<const intern_string_t, json_ptr_walk::walk_list_t>::const_iterator pair_iter;
|
||||
for (pair_iter = ldh.ldh_json_pairs.begin();
|
||||
pair_iter != ldh.ldh_json_pairs.end();
|
||||
++pair_iter) {
|
||||
pair_iter != ldh.ldh_json_pairs.end();
|
||||
++pair_iter) {
|
||||
for (size_t lpc = 0; lpc < pair_iter->second.size(); lpc++) {
|
||||
lnav_data.ld_rl_view->add_possibility(LNM_SQL, "*",
|
||||
ldh.format_json_getter(pair_iter->first, lpc));
|
||||
|
@ -175,7 +175,7 @@ public:
|
||||
|
||||
qname = sql_quote_ident(field.get());
|
||||
jget = sqlite3_mprintf("jget(%s,%Q)", qname.in(),
|
||||
this->ldh_json_pairs[field][index].first.c_str());
|
||||
this->ldh_json_pairs[field][index].wt_ptr.c_str());
|
||||
retval = std::string(jget);
|
||||
|
||||
return retval;
|
||||
@ -192,7 +192,7 @@ public:
|
||||
std::auto_ptr<data_parser> ldh_parser;
|
||||
std::auto_ptr<column_namer> ldh_namer;
|
||||
std::vector<logline_value> ldh_line_values;
|
||||
std::map<const intern_string_t, json_ptr_walk::pair_list_t> ldh_json_pairs;
|
||||
std::map<const intern_string_t, json_ptr_walk::walk_list_t> ldh_json_pairs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -101,6 +101,7 @@ public:
|
||||
virtual void get_foreign_keys(std::vector<std::string> &keys_inout)
|
||||
{
|
||||
keys_inout.push_back("log_line");
|
||||
keys_inout.push_back("min(log_line)");
|
||||
keys_inout.push_back("log_mark");
|
||||
};
|
||||
|
||||
|
@ -69,10 +69,10 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "client cancel\n");
|
||||
}
|
||||
|
||||
for (json_ptr_walk::pair_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
|
||||
iter != jpw.jpw_values.end();
|
||||
++iter) {
|
||||
printf("%s = %s\n", iter->first.c_str(), iter->second.c_str());
|
||||
printf("%s = %s\n", iter->wt_ptr.c_str(), iter->wt_value.c_str());
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
Loading…
Reference in New Issue
Block a user