Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lighthouse-logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
'use strict';

const debug = require('debug');
const marky = require('marky');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


const EventEmitter = require('events').EventEmitter;
const isWindows = process.platform === 'win32';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -207,5 +219,10 @@ class Log {
}

Log.events = new Emitter();
Log.takeTimeEntries = _ => {
const entries = marky.getEntries();
marky.clear();
return entries;
};

module.exports = Log;
5 changes: 3 additions & 2 deletions lighthouse-logger/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 4 additions & 0 deletions lighthouse-logger/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
9 changes: 9 additions & 0 deletions typings/lighthouse-logger/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}