DocSpace-buildtools/common/ASC.Socket.IO/app/log.js

33 lines
849 B
JavaScript
Raw Normal View History

2020-08-02 20:12:45 +00:00
const winston = require('winston');
require('winston-daily-rotate-file')
const path = require('path');
const config = require('../config');
const fs = require('fs');
const fileName = config.get("logPath") || path.join(__dirname, "..", "..", "Logs", "web.socketio.%DATE%.log");
const dirName = path.dirname(fileName);
if (!fs.existsSync(dirName)) {
fs.mkdirSync(dirName);
}
const fileTransport = new (winston.transports.DailyRotateFile)(
{
filename: fileName,
datePattern: 'MM-DD',
handleExceptions: true,
humanReadableUnhandledException: true,
zippedArchive: true,
maxSize: '50m',
maxFiles: '30d'
});
const transports = [
new (winston.transports.Console)(),
fileTransport
];
winston.handleExceptions(fileTransport);
module.exports = new winston.Logger({ transports: transports, exitOnError: false});