In the future, we might be able to use a proxy object here or some other wizadry? I'm not sure.master
parent
31a75b5589
commit
009d6335a0
@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
import Ansi from './Ansi.mjs';
|
||||
|
||||
class Log {
|
||||
// Destructure the awilix container
|
||||
constructor({ settings, ansi }) {
|
||||
this.settings = settings;
|
||||
/** @type {Ansi} */
|
||||
this.a = ansi;
|
||||
|
||||
this.start_time = new Date();
|
||||
|
||||
// FUTURE: We could add a log target (e.g. a file etc.) here if required
|
||||
}
|
||||
|
||||
log_raw(func, ...items) {
|
||||
let prefix = (new Date()).toISOString();
|
||||
if(this.settings.logging.date_display_mode == "relative") {
|
||||
prefix = (new Date() - this.start_time).toFixed(5);
|
||||
}
|
||||
|
||||
func(`${this.a.locol}[${prefix}]${this.a.reset}`, ...items);
|
||||
}
|
||||
log(...items) { this.log_raw(console.log, ...items); }
|
||||
info(...items) { this.log_raw(console.info, ...items); }
|
||||
debug(...items) { this.log_raw(console.debug, ...items); }
|
||||
warn(...items) {
|
||||
this.log_raw(console.warn,
|
||||
this.a.hicol + this.a.fyellow,
|
||||
...items,
|
||||
this.a.reset
|
||||
);
|
||||
}
|
||||
error(...items) {
|
||||
this.log_raw(console.error,
|
||||
this.a.hicol + this.a.fred,
|
||||
...items,
|
||||
this.a.reset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Log;
|
Loading…
Reference in new issue