mirror of https://github.com/tstack/lnav.git
[json-format] fix json file recognition for crlf line-endings
Fixes #528
This commit is contained in:
parent
00ed12557b
commit
3e457e30ca
|
@ -520,6 +520,9 @@ bool line_buffer::read_line(off_t &offset, line_value &lv, bool include_delim)
|
|||
lv.lv_len += 1;
|
||||
}
|
||||
else {
|
||||
if (lv.lv_len > 1 && line_start[lv.lv_len - 1] == '\r') {
|
||||
lv.lv_len -= 1;
|
||||
}
|
||||
offset += 1; /* Skip the delimiter. */
|
||||
}
|
||||
if (offset >= this->lb_last_line_offset) {
|
||||
|
|
|
@ -519,7 +519,18 @@ log_format::scan_result_t external_log_format::scan(nonstd::optional<logfile *>
|
|||
yajl_handle handle = this->jlf_yajl_handle.in();
|
||||
json_log_userdata jlu(sbr);
|
||||
|
||||
if (sbr.empty() || sbr.get_data()[sbr.length() - 1] != '}') {
|
||||
if (sbr.empty()) {
|
||||
return log_format::SCAN_INCOMPLETE;
|
||||
}
|
||||
|
||||
const unsigned char *line_data = (const unsigned char *) sbr.get_data();
|
||||
size_t line_end = sbr.length() - 1;
|
||||
|
||||
while (line_end > 0 && isspace(line_data[line_end])) {
|
||||
line_end -= 1;
|
||||
}
|
||||
|
||||
if (line_end == 0 || line_data[line_end] != '}') {
|
||||
return log_format::SCAN_INCOMPLETE;
|
||||
}
|
||||
|
||||
|
@ -536,8 +547,7 @@ log_format::scan_result_t external_log_format::scan(nonstd::optional<logfile *>
|
|||
jlu.jlu_line_value = sbr.get_data();
|
||||
jlu.jlu_line_size = sbr.length();
|
||||
jlu.jlu_handle = handle;
|
||||
if (yajl_parse(handle,
|
||||
(const unsigned char *)sbr.get_data(), sbr.length()) == yajl_status_ok &&
|
||||
if (yajl_parse(handle, line_data, sbr.length()) == yajl_status_ok &&
|
||||
yajl_complete_parse(handle) == yajl_status_ok) {
|
||||
for (int lpc = 0; lpc < jlu.jlu_sub_line_count; lpc++) {
|
||||
ll.set_sub_offset(lpc);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{"ts": "2013-09-06T20:00:48.124817Z", "lvl": "TRACE", "msg": "trace test"}
|
||||
{"ts": "2013-09-06T20:00:49.124817Z", "lvl": "INFO", "msg": "Starting up service"}
|
||||
{"ts": "2013-09-06T22:00:49.124817Z", "lvl": "INFO", "msg": "Shutting down service", "user": "steve@example.com"}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG5", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG4", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG3", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG2", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "STATS", "msg": "1 beat per second"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "WARNING", "msg": "not looking good"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "ERROR", "msg": "looking bad"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "CRITICAL", "msg": "sooo bad"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "FATAL", "msg": "shoot", "obj": { "field1" : "hi", "field2": 2 }, "arr" : ["hi", {"sub1": true}]}
|
||||
{"ts": "2013-09-06T20:00:48.124817Z", "lvl": "TRACE", "msg": "trace test"}
|
||||
{"ts": "2013-09-06T20:00:49.124817Z", "lvl": "INFO", "msg": "Starting up service"}
|
||||
{"ts": "2013-09-06T22:00:49.124817Z", "lvl": "INFO", "msg": "Shutting down service", "user": "steve@example.com"}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG5", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG4", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG3", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG2", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:00:59.124817Z", "lvl": "DEBUG", "msg": "Details..."}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "STATS", "msg": "1 beat per second"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "WARNING", "msg": "not looking good"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "ERROR", "msg": "looking bad"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "CRITICAL", "msg": "sooo bad"}
|
||||
{"ts": "2013-09-06T22:01:49.124817Z", "lvl": "FATAL", "msg": "shoot", "obj": { "field1" : "hi", "field2": 2 }, "arr" : ["hi", {"sub1": true}]}
|
||||
|
|
Loading…
Reference in New Issue