framez-server/Server/Utils/Logger.js

56 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

/**
* NPM Modules
*/
const fs = require('fs');
const path = require('path');
const winston = require('winston');
/**
* Internal Modules
*/
const Config = require('../Config/Config');
/**
* Module Variables
*/
const tsFormat = () => (new Date()).toISOString().replace(/T/, ' ');
let logger;
/**
* Module Functions
*/
let _init = ()=>{
if (!fs.existsSync(Config.logging.logsPath)) {
fs.mkdirSync(Config.logging.logsPath);
}
// { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
logger = new (winston.Logger)({
transports: [
//Console Logging
new (winston.transports.Console)({
timestamp: tsFormat,
colorize: true,
json: false,
level: Config.logging.consoleLogLevel
}),
// File Logging
new (require('winston-daily-rotate-file'))({
filename: `${Config.logging.logsPath}/framez-server-%DATE%.log`,
timestamp: tsFormat,
datePattern: 'YYYY-MM-DD',
prepend: true,
json: false,
level: Config.logging.fileLogLevel
})
]
});
};
_init();
/**
* Module exported Interface
*/
module.exports = logger;