1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/logging/logger.ts
2018-12-19 13:16:45 -05:00

44 lines
876 B
TypeScript

import { LogLevel, getLevelByName, getLevelName } from "./levels.ts";
export class Logger {
level: number;
levelName: string;
handlers: any[];
constructor(levelName, handlers) {
this.level = getLevelByName(levelName);
this.levelName = levelName;
this.handlers = handlers;
}
_log(level, ...args) {
this.handlers.forEach(handler => {
handler.handle(level, ...args);
});
}
log(level, ...args) {
if (this.level > level) return;
return this._log(level, ...args);
}
debug(...args) {
return this.log(LogLevel.DEBUG, ...args);
}
info(...args) {
return this.log(LogLevel.INFO, ...args);
}
warning(...args) {
return this.log(LogLevel.WARNING, ...args);
}
error(...args) {
return this.log(LogLevel.ERROR, ...args);
}
critical(...args) {
return this.log(LogLevel.CRITICAL, ...args);
}
}