fix(logger): fix isEnabledFor, _log, makeRecord, and manager property
Fix isEnabledFor() to correctly cache and return level check results instead of always caching false. Fix _log() to call handle() after creating the LogRecord. Fix makeRecord() to use Object.keys() and template literal. Add manager getter and fix setter to actually assign the value.
This commit is contained in:
parent
340b31bc50
commit
e76d8fb77b
1 changed files with 18 additions and 10 deletions
|
|
@ -108,10 +108,13 @@ export class Logger extends Filterer {
|
|||
|
||||
public set level(level: LogLevel) { this._level = checkLevel(level) }
|
||||
|
||||
public get manager(): Manager|null { return this._manager }
|
||||
|
||||
public set manager(manager: Manager) {
|
||||
if (this.manager) {
|
||||
if (this._manager) {
|
||||
throw new ValueError('logger can only be assigned to manager once');
|
||||
}
|
||||
this._manager = manager;
|
||||
}
|
||||
|
||||
public setLevel(level: LogLevel) {
|
||||
|
|
@ -143,13 +146,17 @@ export class Logger extends Filterer {
|
|||
public isEnabledFor(level: LogLevel): boolean {
|
||||
if (this.disabled) { return false }
|
||||
|
||||
if (this.cache[level] === undefined && this.manager && this.manager.disable < level) {
|
||||
return this.cache[level] = (
|
||||
level >= this.getEffectiveLevel()
|
||||
);
|
||||
if (level in this.cache) {
|
||||
return this.cache[level];
|
||||
}
|
||||
|
||||
return this.cache[level] = false;
|
||||
if (this._manager && this._manager.disable >= level) {
|
||||
this.cache[level] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.cache[level] = level >= this.getEffectiveLevel();
|
||||
return this.cache[level];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -191,9 +198,9 @@ export class Logger extends Filterer {
|
|||
|
||||
var [k, v] = item;
|
||||
|
||||
if (['message', 'asctime'].includes(k as string) ||
|
||||
(rv as {[key: string]: any}).keys().includes(k as string)) {
|
||||
throw new KeyError('attempt to overwrite ${k} in LogRecord')
|
||||
if (['message', 'asctime'].includes(k) ||
|
||||
Object.keys(rv).includes(k)) {
|
||||
throw new KeyError(`attempt to overwrite ${k} in LogRecord`)
|
||||
}
|
||||
|
||||
(rv as any)[k] = options.extra![k as string] as any
|
||||
|
|
@ -226,7 +233,8 @@ export class Logger extends Filterer {
|
|||
}
|
||||
}
|
||||
|
||||
var record = this.makeRecord(this.scope, level, msg, options)
|
||||
const record = this.makeRecord(this.scope, level, msg, options);
|
||||
this.handle(this.scope, record);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue