-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52ba4f7
commit 86909d3
Showing
7 changed files
with
460 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# production | ||
/build | ||
/logs | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//Bringing Winston in | ||
const winston = require("winston"); | ||
|
||
//Simple function to return the current date and time | ||
const timeStamp = () => { | ||
return new Date(Date.now()).toUTCString(); | ||
}; | ||
|
||
//Here we create our Custom Logger class | ||
class CustomLogger { | ||
|
||
//We want to attach the service route to each instance, so when we call it from our services it gets attached to the message | ||
constructor(service) { | ||
this.log_data = null; | ||
this.service = service; | ||
|
||
const logger = winston.createLogger({ | ||
transports: [ | ||
//Here we declare the winston transport, and assign it to our file: allLogs.log | ||
new winston.transports.File({ | ||
filename: `./logs/allLogs.log`, | ||
}), | ||
], | ||
|
||
format: winston.format.printf((info) => { | ||
|
||
//Here is our custom message | ||
let message = `${timeStamp()} | ${info.level} | ${info.message} | From: ${service} controller `; | ||
|
||
return message; | ||
}), | ||
}); | ||
|
||
this.logger = logger; | ||
} | ||
|
||
setLogData(log_data) { | ||
this.log_data = log_data; | ||
} | ||
|
||
async info(message) { | ||
this.logger.log("info", message); | ||
} | ||
|
||
async info(message, obj) { | ||
this.logger.log("info", message, { | ||
obj, | ||
}); | ||
} | ||
|
||
async debug(message) { | ||
this.logger.log("debug", message); | ||
} | ||
|
||
async debug(message, obj) { | ||
this.logger.log("debug", message, { | ||
obj, | ||
}); | ||
} | ||
|
||
async error(message) { | ||
this.logger.log("error", message); | ||
} | ||
async error(message, obj) { | ||
this.logger.log("error", message, { | ||
obj, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = CustomLogger; |
Oops, something went wrong.