| // 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 androidlogSummary = {}; |
| |
| /** |
| * RegExp for android log line. |
| * @type {RegExp} |
| */ |
| androidlogSummary.CONNECTIVITY_SERVICE = / ConnectivityService: /; |
| |
| /** |
| * Array of Objects holding regexs and handlers for Android subsections |
| * @type {Object[]} |
| * @return {string} handler functions return log line tag label |
| */ |
| androidlogSummary.taggedLines = { |
| 'supplicant_disconnected': { |
| re: /wpa_supplicant: wlan0: CTRL-EVENT-DISCONNECTED /, |
| handler: function(processingState, result) { |
| logHelper.addNote(processingState.wifiStateMachine, |
| processingState.time, |
| result[0]); |
| } |
| } |
| }; |
| |
| /** |
| * 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. |
| * @param {LogSummary} logSummary Object to hold processed log state. |
| * @return {Object[]} Returns an Object[] of text and anchor labels if the log |
| * was processed, null if the log is not a recognized format. |
| */ |
| androidlogSummary.processLogLines = function(logLines, logSummary) { |
| |
| /** |
| * Object used for passing state between main processing loop and |
| * regeular expression handler functions. |
| * @constructor |
| * @type {Object} |
| * @param {LogSummary} logSummary object holding log state after processing |
| * @param {String} time timestamp of current log line |
| * @param {String[]} results results from regex test |
| */ |
| function AndroidlogProcessingState(logSummary, time, results) { |
| this.logSummary = logSummary; |
| this.time = time; |
| this.results = results; |
| } |
| |
| var logLineTime; |
| var logText = []; |
| var parsedLogLineTime; |
| var processingState = new AndroidlogProcessingState(logSummary, null, null); |
| var logType = 'android'; |
| |
| for (var i = 0; i < logLines.length; i++) { |
| console.log('processing log line: ' + logLines[i]); |
| logLineTime = logLines[i].match(logHelper.ANDROID_TIME_FORMAT); |
| if (logLineTime === null) { |
| console.log('not a valid time... skip the log line'); |
| continue; |
| } |
| processingState.time = logLineTime[0]; |
| parsedLogLineTime = Date.parse(processingState.time); |
| |
| if (logSummary.logStartTime == -1) { |
| logSummary.logStartTime = parsedLogLineTime; |
| // This is the start of our log so we need to add the first |
| // WifiStateMachine instance. |
| processingState.wifiStateMachine = |
| new WifiStateMachine(1, |
| parsedLogLineTime, |
| logHelper.getOffsetMS(processingState.time)); |
| logSummary.wifiStateMachines.push(processingState.wifiStateMachine); |
| } |
| |
| if (parsedLogLineTime < logSummary.logEndTime) { |
| console.log('warning: log time has rolled back, check timezone'); |
| } else { |
| logSummary.logEndTime = parsedLogLineTime; |
| } |
| |
| var tempLogText = {text: logLines[i], |
| tag: null, |
| type: 'basic', |
| file: logType, |
| ts: parsedLogLineTime}; |
| |
| for (var taggedLine in androidlogSummary.taggedLines) { |
| var result = logLines[i].match( |
| androidlogSummary.taggedLines[taggedLine].re); |
| if (result !== null) { |
| tempLogText.type = |
| androidlogSummary.taggedLines[taggedLine].handler(processingState, |
| result); |
| // Since this line does have a match with the flagged log lines, create |
| // a tag that allows the summary notes to link to the displayed log. |
| tempLogText.tag = processingState.time; |
| break; |
| } |
| } |
| |
| logText.push(tempLogText); |
| } |
| if (logSummary.wifiStateMachines.length > 0) { |
| logSummary.wifiStateMachines[logSummary.wifiStateMachines.length - 1] |
| .endTime = logSummary.logEndTime; |
| } |
| return logText; |
| }; |
| |
| /** |
| * This method processes each log line in the supplied String array to determine |
| * if the log is an android log. |
| * |
| * @param {String[]} logLines String array for lines in a log. |
| * @return {boolean} Returns true is the log is an android log, false otherwise. |
| */ |
| androidlogSummary.androidlogTypeCheck = function(logLines) { |
| for (var i = 0; i < logLines.length; i++) { |
| if (logHelper.ANDROID_MAIN_SECTION.test(logLines[i]) || |
| logHelper.ANDROID_BUG_REPORT.test(logLines[i]) || |
| androidlogSummary.CONNECTIVITY_SERVICE.test(logLines[i])) { |
| return true; |
| } |
| } |
| return false; |
| }; |