34 lines
853 B
TypeScript
34 lines
853 B
TypeScript
import logger, {Writer, Level} from 'log'
|
|
|
|
export * as log from 'log'
|
|
export default logger
|
|
|
|
export class Counter extends Writer {
|
|
private readonly calls = {
|
|
debug: 0,
|
|
trace: 0,
|
|
info: 0,
|
|
warn: 0,
|
|
error: 0,
|
|
}
|
|
|
|
public constructor() {
|
|
super({minLevel: Level.DEBUG, with_color: false});
|
|
}
|
|
|
|
protected write(level: Level, ..._data: any[]): void {
|
|
switch (level) {
|
|
case Level.DEBUG: this.calls.debug++; break
|
|
case Level.TRACE: this.calls.trace++; break
|
|
case Level.INFO: this.calls.info++; break
|
|
case Level.WARNING: this.calls.warn++; break
|
|
case Level.ERROR: this.calls.error++; break
|
|
default: throw new Error(`Unknown level: ${level}`)
|
|
}
|
|
}
|
|
|
|
public get count() {
|
|
return this.calls
|
|
}
|
|
}
|