Initial commit
This commit is contained in:
46
remote/src/utils/logger.js
Normal file
46
remote/src/utils/logger.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const winston = require('winston');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const paths = require('./paths');
|
||||
|
||||
const logDir = path.join(paths.getBasePath(), 'logs');
|
||||
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, { recursive: true });
|
||||
}
|
||||
|
||||
const baseLogger = winston.createLogger({
|
||||
level: process.env.LOG_LEVEL || 'info',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.splat(),
|
||||
winston.format.json()
|
||||
),
|
||||
defaultMeta: { service: 'remote-screen' },
|
||||
transports: [
|
||||
new winston.transports.File({
|
||||
filename: path.join(logDir, 'error.log'),
|
||||
level: 'error'
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: path.join(logDir, 'combined.log')
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && !process.pkg) {
|
||||
baseLogger.add(new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple()
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
function createLogger(moduleName) {
|
||||
return baseLogger.child({ module: moduleName });
|
||||
}
|
||||
|
||||
module.exports = baseLogger;
|
||||
module.exports.createLogger = createLogger;
|
||||
Reference in New Issue
Block a user