| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /*
- Copyright 2021 Intel Corporation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- function parseLine(entry)
- {
- var test = entry.match(/^\[.*M\]/);
- if (test == null)
- {
- test = entry.match(/\[.+ => .+:[0-9]+\]/);
- if (test != null)
- {
- // Windows Crash Entry
- var file = test[0].substring(1).match(/(?!.+ ).+(?=:)/);
- var line = test[0].match(/(?!:)[0-9]+(?=\]$)/);
- var fn = test[0].match(/(?!\[).+(?= =>)/);
- if (file != null) { this.results.peek().f = file[0].trim(); }
- if (line != null) { this.results.peek().l = line[0]; }
- if (fn != null) { this.results.peek().fn = fn[0]; }
- }
- else
- {
- test = entry.match(/^[\.\/].+\(\) \[0x[0-9a-fA-F]+\]$/);
- if (test != null)
- {
- // Linux Crash Stack with no symbols
- test = test[0].match(/(?!\[)0x[0-9a-fA-F]+(?=\]$)/);
- if (test != null)
- {
- if (this.results.peek().sx == null) { this.results.peek().sx = []; }
- this.results.peek().sx.unshift(test[0]);
- }
- }
- else
- {
- test = entry.match(/^\[.+_[0-9a-fA-F]{16}\]$/);
- if(test!=null)
- {
- // Linux Crash ID
- test = test[0].match(/(?!_)[0-9a-fA-F]{16}(?=\]$)/);
- this.results.peek().h = test[0];
- }
- }
- test = entry.match(/(?!^=>)\/+.+:[0-9]+$/);
- if(test!=null)
- {
- // Linux Crash Entry
- if (this.results.peek().s == null) { this.results.peek().s = []; }
- this.results.peek().s.unshift(test[0]);
- }
-
- }
- return;
- }
- test = test[0];
- var dd = test.substring(1, test.length -1);
- var c = dd.split(' ');
- var t = c[1].split(':');
- if (c[2] == 'PM') { t[0] = parseInt(t[0]) + 12; if (t[0] == 24) { t[0] = 0; } }
- var d = Date.parse(c[0] + 'T' + t.join(':'));
- var msg = entry.substring(test.length).trim();
- var hash = msg.match(/^\[[0-9a-fA-F]{16}\]/);
- if (hash != null)
- {
- hash = hash[0].substring(1, hash[0].length - 1);
- msg = msg.substring(hash.length + 2).trim();
- }
- else
- {
- hash = msg.match(/^\[\]/);
- if(hash!=null)
- {
- msg = msg.substring(2).trim();
- hash = null;
- }
- }
- var log = { t: Math.floor(d / 1000), m: msg };
- if (hash != null) { log.h = hash; }
- // Check for File/Line in generic log entry
- test = msg.match(/^.+:[0-9]+ \([0-9]+,[0-9]+\)/);
- if (test != null)
- {
- log.m = log.m.substring(test[0].length).trim();
- log.f = test[0].match(/^.+(?=:[0-9]+)/)[0];
- log.l = test[0].match(/(?!:)[0-9]+(?= \([0-9]+,[0-9]+\)$)/)[0];
- }
- this.results.push(log);
- }
- function readLog_data(buffer)
- {
- var lines = buffer.toString();
- if (this.buffered != null) { lines = this.buffered + lines; }
- lines = lines.split('\n');
- var i;
- for (i = 0; i < (lines.length - 1) ; ++i)
- {
- parseLine.call(this, lines[i]);
- }
- if (lines.length == 1)
- {
- parseLine.call(this, lines[0]);
- this.buffered = null;
- }
- else
- {
- this.buffered = lines[lines.length - 1];
- }
- }
- function readLogEx(path)
- {
- var ret = [];
- try
- {
- var s = require('fs').createReadStream(path);
- s.buffered = null;
- s.results = ret;
- s.on('data', readLog_data);
- s.resume();
- if (s.buffered != null) { readLog_data.call(s, s.buffered); s.buffered = null; }
- s.removeAllListeners('data');
- s = null;
- }
- catch(z)
- {
- }
- return (ret);
- }
- function readLog(criteria, path)
- {
- var objects = readLogEx(path == null ? (process.execPath.split('.exe').join('') + '.log') : path);
- var ret = [];
- if (typeof (criteria) == 'string')
- {
- try
- {
- var dstring = Date.parse(criteria);
- criteria = Math.floor(dstring / 1000);
- }
- catch(z)
- {
- }
- }
- if (typeof (criteria) == 'number')
- {
- if(criteria < 1000)
- {
- // Return the last xxx entries
- ret = objects.slice(objects.length - ((criteria > objects.length) ? objects.length : criteria));
- }
- else
- {
- // Return entries that are newer than xxx
- var i;
- for (i = 0; i < objects.length && objects[i].t <= criteria; ++i) { }
- ret = objects.slice(i);
- }
- }
- else
- {
- ret = objects;
- }
- return (ret);
- }
- module.exports = { read: readLog, readEx: readLogEx }
|