67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
class Logger {
|
|
/**
|
|
*
|
|
* @param {string} m Module Name
|
|
* @param {string} e Endpoint Function Name
|
|
*/
|
|
constructor(m, e) {
|
|
this.__module = m;
|
|
this.__endpoint = e;
|
|
this.log = this.log.bind(this);
|
|
this.start = this.start.bind(this);
|
|
this.error = this.error.bind(this);
|
|
this.success = this.success.bind(this);
|
|
this.__getVString = this.__getVString.bind(this);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {object} v variables to log
|
|
*/
|
|
__getVString(v = {}) {
|
|
var vString = '';
|
|
Object.keys(v).map((k) => (vString += `${k}: ${v[k]} `));
|
|
return vString;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string} e error message
|
|
* @param {object} v variables to log
|
|
*/
|
|
error(e = 'ERROR LOG', v = {}) {
|
|
console.error(`[ERROR] ${this.__module} / ${this.__endpoint} / ${e}\t ${this.__getVString(v)}`);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {object} v variables to log
|
|
*/
|
|
start(v = {}) {
|
|
console.info(`[START] ${this.__module} / ${this.__endpoint}\t ${this.__getVString(v)}`);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string} m log message
|
|
* @param {object} v variables to log
|
|
*/
|
|
success(m = '', v = {}) {
|
|
console.info(`[DONE] ${this.__module} / ${this.__endpoint} / ${m}\t ${this.__getVString(v)}`);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string} d description like [DONE, ERROR, INFO]
|
|
* @param {string} m log message
|
|
* @param {object} v variables to log
|
|
*/
|
|
log(d = 'CUSTOM', m = '', v = {}) {
|
|
console.info(
|
|
`[(${d})] ${this.__module} / ${this.__endpoint} / ${m} \t ${this.__getVString(v)}`
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = Logger;
|