Files
logger-counter/index.ts
T

36 lines
957 B
TypeScript

import logger, {type Writer, Level, type WriterOptions} from 'log'
export * as log from 'log'
export default logger
export class Counter implements Writer {
readonly _options: WriterOptions = {minLevel: Level.DEBUG, with_color: false}
private readonly calls = {
debug: 0,
trace: 0,
info: 0,
warn: 0,
error: 0,
}
public constructor() {}
log(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}`)
}
}
get options() : WriterOptions {
return this._options
}
public get count() {
return this.calls
}
}