blob: 0bcebd24310013a6466252aad1ad99bd2396c0d5 [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview Class for processing network_event_log messages.
*/
let networkEventLogSummary = {};
/**
* Objects holding regexs and handlers for log subsections
* @type {Object}
*/
networkEventLogSummary.taggedLines = {
'error': {
re: /(ERROR )(.*$)/,
handler: function(result) {
return 'error';
}
},
'user': {
re: /(USER )(.*$)/,
handler: function(result) {
return 'user';
}
},
};
/**
* @param {Array<string>} logLines
* @param {LogSummary} logSummary
* @return {Array<Object>} Returns an Array of Objects with text and anchor
* labels if the log was processed, null if |logLines| is invalid.
*/
networkEventLogSummary.processLogLines = function(logLines, logSummary) {
const logType = 'eventLog';
let logStart = -1;
let logText = [];
for (var i = 0; i < logLines.length; i++) {
// do we have a start time?
const time = logLines[i].match(logHelper.TIME_FORMAT);
if (time == null) {
console.log('logline: ', logLines[i]);
console.log('not a valid time... continue');
continue;
}
logHelper.getOffsetMS(time);
const timeCheck = Date.parse(time[0]);
if (logStart == -1 && time !== null) {
logStart = time[0];
logSummary.logStartTime = timeCheck;
logSummary.prevLogLineTime = logSummary.logStartTime;
}
if (timeCheck < logSummary.logEndTime) {
console.log('warning: log time has rolled back, check timezone');
} else {
logSummary.logEndTime = timeCheck;
logSummary.prevLogLineTime = timeCheck;
}
console.log('log_line: ' + logLines[i]);
var tempLogText = {text: logLines[i],
tag: null,
type: 'basic',
file: logType,
ts: timeCheck};
for (var taggedLine in networkEventLogSummary.taggedLines) {
var result =
logLines[i].match(networkEventLogSummary.taggedLines[taggedLine].re);
if (result !== null) {
tempLogText.type =
networkEventLogSummary.taggedLines[taggedLine].handler(result);
tempLogText.tag = time[0];
break;
}
}
logText.push(tempLogText);
}
console.log('this is the end of our log...');
return logText;
};