Commit 70c952fc authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Added logging date to websocket logs

parent 3c12fc1b
...@@ -8,12 +8,13 @@ var CallbackLogger = winston.transports.CallbackLogger = function (options) { ...@@ -8,12 +8,13 @@ var CallbackLogger = winston.transports.CallbackLogger = function (options) {
this.name = 'customLogger'; this.name = 'customLogger';
this.level = options.level || 'info'; this.level = options.level || 'info';
this.callback = options.callback; this.callback = options.callback;
this.timestamp = options.timestamp;
}; };
util.inherits(CallbackLogger, winston.Transport); util.inherits(CallbackLogger, winston.Transport);
CallbackLogger.prototype.log = function (level, msg, meta, callback) { CallbackLogger.prototype.log = function (level, msg, meta, callback) {
this.callback(level, msg); this.callback(level, msg, this.timestamp());
callback(null, true); callback(null, true);
}; };
......
...@@ -55,15 +55,17 @@ module.exports = function(dbConf, overConf, interfaces, httpLogs) { ...@@ -55,15 +55,17 @@ module.exports = function(dbConf, overConf, interfaces, httpLogs) {
})); }));
// The callback which write each new log message to websocket // The callback which write each new log message to websocket
logger.addCallbackLogs((level, msg) => { logger.addCallbackLogs((level, msg, timestamp) => {
lastLogs.splice(0, Math.max(0, lastLogs.length - constants.WEBMIN_LOGS_CACHE + 1)); lastLogs.splice(0, Math.max(0, lastLogs.length - constants.WEBMIN_LOGS_CACHE + 1));
lastLogs.push({ lastLogs.push({
timestamp: timestamp,
level: level, level: level,
msg: msg msg: msg
}); });
wssEvents.broadcast(JSON.stringify({ wssEvents.broadcast(JSON.stringify({
type: 'log', type: 'log',
value: [{ value: [{
timestamp: timestamp,
level: level, level: level,
msg: msg msg: msg
}] }]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment