feat(log-record): add message, name, msg, args fields and getMessage

This commit is contained in:
Tiara Rodney 2026-03-13 23:09:50 +01:00
parent 3dce9422ae
commit c0ced4cda2
No known key found for this signature in database
GPG key ID: 5CD8EC1D46106723

View file

@ -48,13 +48,32 @@ export class LogRecord {
public readonly levelno: LogLevel; public readonly levelno: LogLevel;
public readonly levelname: string|LogLevel; public readonly levelname: string|LogLevel;
public readonly scope: string; public readonly scope: string;
public readonly name: string;
public readonly msg: string;
public readonly args: any[]|undefined;
public message: string = '';
public readonly created: MillisecondsSinceUnixEpoch = Date.now(); public readonly created: MillisecondsSinceUnixEpoch = Date.now();
public asctime: string = '';
constructor(scope: string, options: LogRecordOptions) { constructor(scope: string, options: LogRecordOptions) {
this.levelno = options.level; this.levelno = options.level;
this.levelname = getLevelName(options.level); this.levelname = getLevelName(options.level);
this.scope = scope; this.scope = scope;
this.name = scope;
this.msg = options.msg;
this.args = options.args;
}
getMessage(): string {
let msg = String(this.msg);
if (this.args && this.args.length > 0) {
msg = this.args.reduce(
(s, arg) => s.replace('%s', String(arg)),
msg
);
}
return msg;
} }
} }