misc(logger): add time/timeEnd methods (#5905)
This commit is contained in:
Родитель
d891fbe6e8
Коммит
3ad529d937
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@ debug@^2.6.8:
|
|||
dependencies:
|
||||
ms "2.0.0"
|
||||
|
||||
marky@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/marky/-/marky-1.2.0.tgz#9617ed647bbbea8f45d19526da33dec70606df42"
|
||||
|
||||
ms@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче