better log
This commit is contained in:
parent
9d7ee9da1f
commit
b22c59c072
1 changed files with 13 additions and 1 deletions
|
@ -51,12 +51,24 @@ export default class Logger {
|
||||||
this.logLevel('Error', message, data)
|
this.logLevel('Error', message, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private now(): string {
|
||||||
|
const now = new Date()
|
||||||
|
return padLeft(now.getUTCHours() + '', 2, '0')
|
||||||
|
+ ':' + padLeft(now.getMinutes() + '', 2, '0')
|
||||||
|
+ ':' + padLeft(now.getUTCSeconds() + '', 2, '0') + '.' + now.getMilliseconds()
|
||||||
|
}
|
||||||
|
|
||||||
public logLevel(level: string, message: string, data?: any): void {
|
public logLevel(level: string, message: string, data?: any): void {
|
||||||
this.output.appendLine(
|
this.output.appendLine(
|
||||||
`[${level} - ${new Date().toLocaleTimeString()}] ${message}`
|
`[${level} - ${this.now()}] ${message}`
|
||||||
)
|
)
|
||||||
if (data) {
|
if (data) {
|
||||||
this.output.appendLine(this.data2String(data))
|
this.output.appendLine(this.data2String(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function padLeft(s: string, n: number, pad = ' ') {
|
||||||
|
return pad.repeat(Math.max(0, n - s.length)) + s
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue