Permalink
Browse files

misc(logger): add time/timeEnd methods (#5905)

  • Loading branch information...
patrickhulce committed Aug 24, 2018
1 parent d891fbe commit 3ad529d937a4aa5af4e68575c6780676edd23248
View
@@ -6,6 +6,8 @@
'use strict';
const debug = require('debug');
const marky = require('marky');
const EventEmitter = require('events').EventEmitter;
const isWindows = process.platform === 'win32';
@@ -104,6 +106,16 @@ class Log {
Log._logToStdErr(`${prefix}:${level || ''}`, [method, snippet]);
}
static time({msg, id, args=[]}, level='log') {
marky.mark(id);
Log[level]('status', msg, ...args);
}
static timeEnd({msg, id, args=[]}, level='verbose') {
Log[level]('statusEnd', msg, ...args);
marky.stop(id);
}
static log(title, ...args) {
Log.events.issueStatus(title, args);
return Log._logToStdErr(title, args);
@@ -207,5 +219,10 @@ class Log {
}
Log.events = new Emitter();
Log.takeTimeEntries = _ => {
const entries = marky.getEntries();
marky.clear();
return entries;
};
module.exports = Log;
@@ -1,8 +1,9 @@
{
"name": "lighthouse-logger",
"version": "1.0.1",
"version": "1.1.0",
"license": "Apache-2.0",
"dependencies": {
"debug": "^2.6.8"
"debug": "^2.6.8",
"marky": "^1.2.0"
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -5,12 +5,21 @@
*/
declare module 'lighthouse-logger' {
interface Status {
msg: string;
id: string;
args?: any[];
}
export function setLevel(level: string): void;
export function formatProtocol(prefix: string, data: Object, level?: string): void;
export function log(title: string, ...args: any[]): void;
export function warn(title: string, ...args: any[]): void;
export function error(title: string, ...args: any[]): void;
export function verbose(title: string, ...args: any[]): void;
export function time(status: Status, level?: string): void;
export function timeEnd(status: Status, level?: string): void;
export function reset(): string;
/** Retrieves and clears all stored time entries */
export function takeTimeEntries(): PerformanceEntry[];
export var events: import('events').EventEmitter;
}

0 comments on commit 3ad529d

Please sign in to comment.