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-07-08 14:42:05 +00:00
|
|
|
prefix = ((new Date() - this.start_time) / 1000).toFixed(4);
|
2019-05-29 10:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|