braid/src/logger.ts

35 lines
808 B
TypeScript

var {winston, transports, createLogger, format} = require('winston');
var path = require('path');
// Set this to whatever, by default the path of the script.
var logPath = './logs/';
const tsFormat = () => (new Date().toISOString());
const logFormat = format.combine(format.timestamp(), format.json());
function loggerTransports(logName: string, logLevel: string) {
return [
new transports.File({
filename: path.join(logPath, `${logName}.log`),
timestamp: tsFormat,
level: logLevel
})
]
};
const errorLog = createLogger({
format: logFormat,
transports: loggerTransports('errors', 'debug')
});
const accessLog = createLogger({
format: logFormat,
transports: loggerTransports('access', 'info')
});
module.exports = {
errorLog: errorLog,
accessLog: accessLog
};