mirror of
https://github.com/denoland/deno.git
synced 2024-12-17 21:03:01 -05:00
6624584dd4
Original: 25b88bcf8c
44 lines
876 B
TypeScript
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);
|
|
}
|
|
}
|