refactor
This commit is contained in:
1 parent
92c2b2d6c1
commit
0336170c8d
1 file changed
+15
-36
+15
-36
@@ -74,15 +74,7 @@ class Logger {
|
|||||||
* @param {Object} config.details - Additional details.
|
* @param {Object} config.details - Additional details.
|
||||||
*/
|
*/
|
||||||
info(config) {
|
info(config) {
|
||||||
const logEntry = {
|
const logEntry = this.buildLogEntry("info", config);
|
||||||
level: "info",
|
|
||||||
message: config.message,
|
|
||||||
service: config.service,
|
|
||||||
method: config.method,
|
|
||||||
details: config.details,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.cacheLog(logEntry);
|
this.cacheLog(logEntry);
|
||||||
this.logger.info(config.message, logEntry);
|
this.logger.info(config.message, logEntry);
|
||||||
}
|
}
|
||||||
@@ -96,15 +88,7 @@ class Logger {
|
|||||||
* @param {Object} config.details - Additional details.
|
* @param {Object} config.details - Additional details.
|
||||||
*/
|
*/
|
||||||
warn(config) {
|
warn(config) {
|
||||||
const logEntry = {
|
const logEntry = this.buildLogEntry("warn", config);
|
||||||
level: "warn",
|
|
||||||
message: config.message,
|
|
||||||
service: config.service,
|
|
||||||
method: config.method,
|
|
||||||
details: config.details,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.cacheLog(logEntry);
|
this.cacheLog(logEntry);
|
||||||
this.logger.warn(config.message, logEntry);
|
this.logger.warn(config.message, logEntry);
|
||||||
}
|
}
|
||||||
@@ -118,15 +102,7 @@ class Logger {
|
|||||||
* @param {Object} config.details - Additional details.
|
* @param {Object} config.details - Additional details.
|
||||||
*/
|
*/
|
||||||
error(config) {
|
error(config) {
|
||||||
const logEntry = {
|
const logEntry = this.buildLogEntry("error", config);
|
||||||
level: "error",
|
|
||||||
message: config.message,
|
|
||||||
service: config.service,
|
|
||||||
method: config.method,
|
|
||||||
details: config.details,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.cacheLog(logEntry);
|
this.cacheLog(logEntry);
|
||||||
this.logger.error(config.message, logEntry);
|
this.logger.error(config.message, logEntry);
|
||||||
}
|
}
|
||||||
@@ -139,15 +115,7 @@ class Logger {
|
|||||||
* @param {Object} config.details - Additional details.
|
* @param {Object} config.details - Additional details.
|
||||||
*/
|
*/
|
||||||
debug(config) {
|
debug(config) {
|
||||||
const logEntry = {
|
const logEntry = this.buildLogEntry("debug", config);
|
||||||
level: "debug",
|
|
||||||
message: config.message,
|
|
||||||
service: config.service,
|
|
||||||
method: config.method,
|
|
||||||
details: config.details,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.cacheLog(logEntry);
|
this.cacheLog(logEntry);
|
||||||
this.logger.debug(config.message, logEntry);
|
this.logger.debug(config.message, logEntry);
|
||||||
}
|
}
|
||||||
@@ -162,6 +130,17 @@ class Logger {
|
|||||||
getLogs() {
|
getLogs() {
|
||||||
return this.logCache;
|
return this.logCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildLogEntry(level, config) {
|
||||||
|
return {
|
||||||
|
level,
|
||||||
|
message: config.message,
|
||||||
|
service: config.service,
|
||||||
|
method: config.method,
|
||||||
|
details: config.details,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
|
|||||||
Reference in new issue
Block a user