commit
This commit is contained in:
58
public/js/app/logger.js
Normal file
58
public/js/app/logger.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const winston = require('winston');
|
||||
|
||||
const { createLogger, format, transports } = require('winston');
|
||||
const { combine, timestamp, label, printf, numsession } = format;
|
||||
|
||||
const myFormatFile = printf(({ level, message, label, timestamp, numsession }) => {
|
||||
return `${timestamp} ${level} [${label}] SID[${numsession}] ${message}`;
|
||||
});
|
||||
|
||||
const myFormatConsole = printf(({ level, message, label, timestamp, numsession }) => {
|
||||
return `${timestamp} ${level} [${label}] SID[${numsession}] ${message}`;
|
||||
});
|
||||
|
||||
|
||||
const DailyRotateFile = require('winston-daily-rotate-file');
|
||||
|
||||
|
||||
const logger = winston.createLogger({
|
||||
//level: 'info',
|
||||
format: combine(
|
||||
//label({ label: '' }),
|
||||
timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),
|
||||
myFormatFile
|
||||
),
|
||||
defaultMeta: { service: 'user-service' },
|
||||
transports: [
|
||||
new DailyRotateFile({ filename: 'logs/combined.log' }),
|
||||
],
|
||||
exceptionHandlers: [
|
||||
new DailyRotateFile({ filename: 'logs/combined.log' }),
|
||||
new winston.transports.Console()
|
||||
],
|
||||
rejectionHandlers: [
|
||||
new DailyRotateFile({ filename: 'logs/combined.log' }),
|
||||
new winston.transports.Console()
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
if (process.env.ENV !== 'production' ) {
|
||||
logger.add(new winston.transports.Console(
|
||||
{
|
||||
format: combine(
|
||||
//label({ label: '' }),
|
||||
timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),
|
||||
myFormatConsole
|
||||
),
|
||||
handleExceptions: true //pour afficher également les exceptions dans la console
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// EXPORT DE MODULE POUR QU'IL SOIT LU DANS LES AUTRES FICHIERS JS
|
||||
/////////////////////////////////////////////////
|
||||
module.exports = logger;
|
||||
Reference in New Issue
Block a user