feat(log-record): add message, name, msg, args fields and getMessage
This commit is contained in:
parent
3dce9422ae
commit
c0ced4cda2
1 changed files with 19 additions and 0 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue