1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * This class stores information of one single entry of log
9 var CrosLogEntry = function() {
14 function CrosLogEntry() {
15 // The entry is visible by default
16 this.visibility
= true;
19 CrosLogEntry
.prototype = {
20 //------------------------------------------------------------------------
21 // Log input text parser
22 // Parses network log into tokens like time, name, pid
24 //--------------------------------------------------------------------------
25 tokenizeNetworkLog: function(NetworkLogEntry
) {
26 var tokens
= NetworkLogEntry
.split(' ');
27 var timeTokens
= tokens
[0].split(/[\s|\:|\-|T|\.]/);
29 // List of all parameters for Date Object
30 var year
= timeTokens
[0];
31 var month
= timeTokens
[1];
32 var day
= timeTokens
[2];
33 var hour
= timeTokens
[3];
34 var minute
= timeTokens
[4];
35 var second
= timeTokens
[5];
36 var millisecond
= (parseInt(timeTokens
[6]) / 1000).toFixed(0);
37 this.time
= new Date(year
, month
, day
, hour
, minute
,
40 // Parses for process name and ID.
41 var process
= tokens
[2];
42 if (hasProcessID(process
)) {
43 var processTokens
= process
.split(/[\[|\]]/);
44 this.processName
= processTokens
[0];
45 this.processID
= processTokens
[1];
47 this.processName
= process
.split(/\:/)[0];
48 this.processID
= 'Unknown';
51 // Gets level of the log: error|warning|info|unknown if failed.
52 this.level
= hasLevelInfo(tokens
[3]);
54 // Treats the rest of the entry as description.
55 var descriptionStartPoint
= NetworkLogEntry
.indexOf(tokens
[2]) +
57 this.description
= NetworkLogEntry
.substr(descriptionStartPoint
);
60 // Represents the Date object as a string.
62 return this.time
.getMonth() + '/' + this.time
.getDate() +
63 ' ' + this.time
.getHours() + ':' + this.time
.getMinutes() +
64 ':' + this.time
.getSeconds() + ':' + this.time
.getMilliseconds();
70 * Takes a token as input and searches for '['.
71 * We assume if the token contains '[' it contains a process ID.
73 * @param {string} token A token from log
74 * @return {boolean} true if '[' is found
76 var hasProcessID = function(token
) {
77 return token
!= undefined && token
.indexOf('[') != -1;
82 * Checks if the input token contains level information.
84 * @param {string} token A token from log
85 * @return {string} Level found in the token
87 var hasLevelInfo = function(token
) {
88 if (token
== undefined)
90 if (token
.toLowerCase().indexOf('err') != -1) {
92 } else if (token
.toLowerCase().indexOf('warn') != -1) {
94 } else if (token
.toLowerCase().indexOf('info') != -1) {