UNPKG

@triviality/logger

Version:

Typescript loggers with an interface that support composition

21 lines (15 loc) 635 B
import { LoggerInterface, LogLevel } from './LoggerInterface'; import { AbstractLogLevelLogger } from './AbstractLogLevelLogger'; export class PrefixLogger extends AbstractLogLevelLogger implements LoggerInterface { public static with(logger: LoggerInterface, prefix: string): LoggerInterface { return new this(logger, prefix); } constructor(private readonly logger: LoggerInterface, private readonly prefix: string) { super(); } public log(level: LogLevel, message?: any, ...optionalParams: any[]) { this.logger.log(level, this.prefix + message, ...optionalParams); } }