export class LogLevel {
protected constructor(readonly name: string, readonly severity: number) {
}
gte(other: LogLevel): boolean {
return this.severity >= other.severity;
}
lte(other: LogLevel): boolean {
return this.severity <= other.severity;
}
private static readonly levels: Record<string, LogLevel> = {};
static register(level: LogLevel): LogLevel {
LogLevel.levels[level.name] = level;
return level;
}
static forName(name: string | undefined): LogLevel | undefined {
return name ? LogLevel.levels[name] : undefined;
}
static names(): string[] {
return Object.keys(LogLevel.levels);
}
static TRACE = LogLevel.register(new LogLevel('trace', 0));
static DEBUG = LogLevel.register(new LogLevel('debug', 100));
static INFO = LogLevel.register(new LogLevel('info', 200));
static LOG = LogLevel.register(new LogLevel('log', 300));
static NOTICE = LogLevel.register(new LogLevel('notice', 300));
static WARN = LogLevel.register(new LogLevel('warn', 400));
static ERROR = LogLevel.register(new LogLevel('error', 500));
static CRITICAL = LogLevel.register(new LogLevel('critical', 600));
static ALERT = LogLevel.register(new LogLevel('alert', 700));
static EMERGENCY = LogLevel.register(new LogLevel('emergency', 800));
}
|