chore: complete update
This commit is contained in:
37
resources/js/core/logger.js
Normal file
37
resources/js/core/logger.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import {monitor} from "./frameloop";
|
||||
|
||||
export class Logger {
|
||||
static enabled = true //import.meta.env.MODE !== 'production';
|
||||
|
||||
static log(...args) {
|
||||
this._write('log', '[LOG]', args);
|
||||
}
|
||||
|
||||
static warn(...args) {
|
||||
this._write('warn', '[WARN]', args)
|
||||
}
|
||||
|
||||
static info(...args) {
|
||||
this._write('info', '[INFO]', args);
|
||||
}
|
||||
|
||||
static error(...args) {
|
||||
this._write('error', '[ERROR]', args);
|
||||
}
|
||||
|
||||
static _write(consoleMethod, prefix, args) {
|
||||
if(!this.enabled) return;
|
||||
|
||||
const date = new Date();
|
||||
const timestamp = date.toLocaleTimeString('de-DE');
|
||||
|
||||
const msg = `${prefix} [${timestamp}] ${args.map(a => typeof a === 'object' ? JSON.stringify(a) : a).join(' ')}`;
|
||||
|
||||
if(typeof console[consoleMethod] === 'function') {
|
||||
console[consoleMethod](msg);
|
||||
}
|
||||
|
||||
monitor?.log(msg)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user