Logging is more verbose
This commit is contained in:
Binary file not shown.
@@ -1,9 +1,20 @@
|
||||
const colours = require('colors/safe');
|
||||
const fs = require('fs');
|
||||
|
||||
let LogLevel = 1;
|
||||
let Dialect = 'SQLITE';
|
||||
let logPath = 'logs.log';
|
||||
|
||||
export class Logger {
|
||||
static init(path) {
|
||||
if (path) logPath = path;
|
||||
|
||||
if (!fs.existsSync(logPath)) {
|
||||
fs.writeFileSync(logPath, '');
|
||||
}
|
||||
fs.appendFileSync(logPath, '[SYSTEM STARTING UP] \n');
|
||||
}
|
||||
|
||||
static SetLevel(level) {
|
||||
LogLevel = level;
|
||||
}
|
||||
@@ -20,6 +31,7 @@ export class Logger {
|
||||
static database(message) {
|
||||
if (LogLevel > 0) return;
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.magenta(Dialect) + '] ' + message);
|
||||
}
|
||||
@@ -27,6 +39,7 @@ export class Logger {
|
||||
static middleware(message) {
|
||||
if (LogLevel > 0) return;
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [HTTP-MIDDLEWARE] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.blue('HTTP-MIDDLEWARE') + '] ' + message);
|
||||
}
|
||||
@@ -34,12 +47,14 @@ export class Logger {
|
||||
static debug(message) {
|
||||
if (LogLevel > 1) return;
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.cyan('DEBUG') + '] ' + message);
|
||||
}
|
||||
|
||||
static ready() {
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.rainbow('READY') + ']');
|
||||
}
|
||||
@@ -47,6 +62,7 @@ export class Logger {
|
||||
static info(message) {
|
||||
if (LogLevel > 2) return;
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.green('INFO') + '] ' + message);
|
||||
}
|
||||
@@ -54,18 +70,21 @@ export class Logger {
|
||||
static warn(message) {
|
||||
if (LogLevel > 3) return;
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.yellow('WARN') + '] ' + message);
|
||||
}
|
||||
|
||||
static error(message) {
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.red('ERROR') + '] ' + message);
|
||||
}
|
||||
|
||||
static panic(message) {
|
||||
let d = new Date();
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.red('PANIC') + '] ' + message);
|
||||
process.exit();
|
||||
|
||||
Reference in New Issue
Block a user