diff --git a/src/line_buffer.cc b/src/line_buffer.cc index 67826e8a..52166078 100644 --- a/src/line_buffer.cc +++ b/src/line_buffer.cc @@ -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) { diff --git a/src/log_format.cc b/src/log_format.cc index b516fa9c..d3c2580d 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -519,7 +519,18 @@ log_format::scan_result_t external_log_format::scan(nonstd::optional 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 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); diff --git a/test/logfile_json.json b/test/logfile_json.json index b5018895..ef750dfa 100644 --- a/test/logfile_json.json +++ b/test/logfile_json.json @@ -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}]}