mirror of
https://github.com/aurora-dot/pastel.codes.git
synced 2025-09-02 19:46:52 +01:00
Added winston for logging
This commit is contained in:
40
config/winston.js
Normal file
40
config/winston.js
Normal file
@@ -0,0 +1,40 @@
|
||||
var appRoot = require('app-root-path');
|
||||
var winston = require('winston');
|
||||
|
||||
// define the custom settings for each transport (file, console)
|
||||
var options = {
|
||||
file: {
|
||||
level: 'info',
|
||||
filename: `${appRoot}/logs/app.log`,
|
||||
handleExceptions: true,
|
||||
json: true,
|
||||
maxsize: 5242880, // 5MB
|
||||
maxFiles: 5,
|
||||
colorize: false,
|
||||
},
|
||||
console: {
|
||||
level: 'debug',
|
||||
handleExceptions: true,
|
||||
json: false,
|
||||
colorize: true,
|
||||
},
|
||||
};
|
||||
|
||||
// instantiate a new Winston Logger with the settings defined above
|
||||
var logger = new winston.Logger({
|
||||
transports: [
|
||||
new winston.transports.File(options.file),
|
||||
new winston.transports.Console(options.console)
|
||||
],
|
||||
exitOnError: false, // do not exit on handled exceptions
|
||||
});
|
||||
|
||||
// create a stream object with a 'write' function that will be used by `morgan`
|
||||
logger.stream = {
|
||||
write: function(message, encoding) {
|
||||
// use the 'info' log level so the output will be picked up by both transports (file and console)
|
||||
logger.info(message);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = logger;
|
Reference in New Issue
Block a user