fix(handler): add formatter getter, fix format() return, fix level setter

Add missing getter for formatter property. Fix format() to return
the formatted string instead of discarding it. Fix level setter
to assign to _level instead of recursing infinitely.
This commit is contained in:
Tiara Rodney 2026-03-13 22:40:05 +01:00
parent 03e3641e03
commit 340b31bc50
No known key found for this signature in database
GPG key ID: 5CD8EC1D46106723

View file

@ -78,7 +78,7 @@ export class Handler extends Filterer {
} }
get level(): number { return this._level } get level(): number { return this._level }
set level(level: LogLevel|string) { this.level = checkLevel(level) } set level(level: LogLevel|string) { this._level = checkLevel(level) }
get scope(): string|null { return this._scope } get scope(): string|null { return this._scope }
set scope(scope: string) { this._scope = scope } set scope(scope: string) { this._scope = scope }
@ -90,11 +90,9 @@ export class Handler extends Filterer {
* If a formatter is set, use it. Otherwise, use the default formatter for * If a formatter is set, use it. Otherwise, use the default formatter for
* the module. * the module.
*/ */
format(record: LogRecord) { format(record: LogRecord): string {
var fmt: Formatter|null = null; const fmt = this.formatter ?? DEFAULT_FORMATTER;
return fmt.format(record);
if (this.formatter) { fmt = this.formatter }
else { fmt = DEFAULT_FORMATTER }
} }
/** /**
@ -159,6 +157,7 @@ export class Handler extends Filterer {
) )
} }
get formatter(): Formatter|null { return this._formatter }
set formatter(fmt: Formatter) { this._formatter = fmt } set formatter(fmt: Formatter) { this._formatter = fmt }
} }