Skip to content

Commit

Permalink
refactor logger
Browse files Browse the repository at this point in the history
  • Loading branch information
bitrinjani committed Jan 6, 2018
1 parent 10fd7fa commit f66c512
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/logger/index.ts
Expand Up @@ -4,12 +4,19 @@ import * as util from 'util';

export const options = { enabled: process.env.NODE_ENV === 'test' ? false : true };

export interface Logger {
debug: (s: string, ...args: any[]) => void;
info: (s: string, ...args: any[]) => void;
warn: (s: string, ...args: any[]) => void;
error: (s: string, ...args: any[]) => void;
}

const logger = pino({ level: 'debug' });
const cache = new Map();

export function getLogger(name: string) {
export function getLogger(name: string): Logger {
if (!options.enabled) {
return new Proxy({}, { get: () => _.noop });
return new Proxy({}, { get: () => _.noop }) as Logger;
}
const label = _.trimEnd(name, 'Impl');
if (cache.has(label)) {
Expand Down

0 comments on commit f66c512

Please sign in to comment.