2019-05-29 10:59:40 +00:00
|
|
|
"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) {
|
2019-07-16 17:03:35 +00:00
|
|
|
if(this.settings.logging.date_display_mode == "none") {
|
|
|
|
func(...items);
|
|
|
|
return;
|
|
|
|
}
|
2019-05-29 10:59:40 +00:00
|
|
|
let prefix = (new Date()).toISOString();
|
|
|
|
if(this.settings.logging.date_display_mode == "relative") {
|
2019-08-06 11:42:54 +00:00
|
|
|
prefix = ((new Date() - this.start_time) / 1000).toFixed(3);
|
2019-05-29 10:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func(`${this.a.locol}[${prefix}]${this.a.reset}`, ...items);
|
|
|
|
}
|
2019-08-02 13:00:31 +00:00
|
|
|
log_e(...items) { this.log_raw(console.error, ...items); }
|
2019-05-29 10:59:40 +00:00
|
|
|
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;
|