constructor(appliName) { this.appliName = appliName || 'rasa-ui'; this.logFormat = winston.format.printf(info => { const formattedDate = info.timestamp.replace('T', ' ').replace('Z', ''); return `${formattedDate}|${this.appliName}|${info.level}|${ info.message };`; }); this.winston = winston.createLogger({ level: global.loglevel || 'info', format: winston.format.combine( winston.format.timestamp(), this.logFormat ), transports: [new winston.transports.Console({})] }); }
winston.format(info => { if (info.meta && info.meta instanceof Error) { info.message = `${info.message} ${info.meta.stack}`; } return info; })
winston.format((logEntry) => { const base = { timestamp: new Date() }; const json = Object.assign(base, logEntry); logEntry[MESSAGE] = JSON.stringify(json); return logEntry; })()
logger.add(new winston.transports.Console({ format: winston.format.combine( winston.format.colorize(), winston.format.timestamp(), winston.format.align(), winston.format.printf((debug) => { const { timestamp, level, message, ...args } = debug; const ts = timestamp.slice(0, 19).replace('T', ' '); return `${ts} [${level}]: ${message} ${Object.keys(args).length ? JSON.stringify(args, null, 2) : ''}`; }) ) }));
const characterTruncater = lengthLimit => { return winston.format.combine( winston.format.printf(info => { const m = info.message if (typeof m === 'string') { const tailLength = Math.floor(lengthLimit / 2) const filler = `[${Math.floor(m.length - lengthLimit)} chars]` info.message = (m.length < lengthLimit) ? m : (m.substring(0, tailLength) + filler + m.substring(m.length - tailLength, m.length)) } return info }) ) }