blob: 26ead6dfb5ced5baa49d064c455fc0471ea0ac6f [file] [log] [blame]
// Copyright 2015 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 to hold methods for processing syslog messages.
*/
var syslogSummary = {};
/**
* RegExp for kernel info logging lines.
* @type {RegExp}
*/
syslogSummary.KERNEL_INFO = / kernel: \[/;
/**
* This method processes each log line in the supplied String array. Each log
* line is checked to see if matches one of the regular expressions from the
* logHelper. Each flagged log line is then processed.
*
* @param {String[]} logLines String array for lines in a log.
* @return {Object[]} Returns an Object[] of text and anchor labels if the log
* was processed, null if the log is not a recognized format.
*/
syslogSummary.processLogLines = function(logLines) {
var logText = [];
var time;
for (var i = 0; i < logLines.length; i++) {
time = null;
time = logLines[i].match(logHelper.TIME_FORMAT);
if (time == null) {
continue;
}
var timeCheck = Date.parse(time[0]);
var tempLogText = {text: logLines[i],
tag: time[0],
type: 'basic',
file: 'syslog',
ts: timeCheck};
tempLogText.tag = null;
logText.push(tempLogText);
}
return logText;
};
/**
* This method processes each log line in the supplied String array to determine
* if the log is a syslog.
*
* @param {String[]} logLines String array for lines in a log.
* @return {boolean} Returns true is the log is a syslog, false otherwise.
*/
syslogSummary.syslogTypeCheck = function(logLines) {
for (var i = 0; i < logLines.length; i++) {
if (syslogSummary.KERNEL_INFO.test(logLines[i])) {
return true;
}
}
return false;
};