diff --git a/api.js b/api.js index ebf272d3..f23d0d9d 100644 --- a/api.js +++ b/api.js @@ -467,7 +467,7 @@ module.exports = done => { emit: (key, message) => log.info('Gelf', JSON.stringify(message)) }; - loggelf = message => { + loggelf = (message, requiredKeys = []) => { if (typeof message === 'string') { message = { short_message: message @@ -484,7 +484,8 @@ module.exports = done => { message.timestamp = Date.now() / 1000; message._component = component; Object.keys(message).forEach(key => { - if (!message[key]) { + if (!message[key] && !requiredKeys.includes(key)) { + // remove the key if it empty/falsy/undefined/null and it is not required to stay delete message[key]; } }); @@ -538,7 +539,7 @@ module.exports = done => { settingsHandler = new SettingsHandler({ db: db.database }); - server.loggelf = message => loggelf(message); + server.loggelf = (message, requiredKeys = []) => loggelf(message, requiredKeys); server.lock = new Lock({ redis: db.redis, diff --git a/lib/api/users.js b/lib/api/users.js index 5eb121eb..2536a505 100644 --- a/lib/api/users.js +++ b/lib/api/users.js @@ -1705,14 +1705,18 @@ module.exports = (db, server, userHandler, settingsHandler) => { }); } - server.loggelf({ - short_message: '[QUOTA] reset', - _mail_action: 'quota', - _user: userData._id, - _set: Number(storageUsed) || 0, - _previous_storage_used: Number(updateResponse.value.storageUsed) || 0, - _storage_used: Number(storageUsed) || 0 - }); + server.loggelf( + { + short_message: '[QUOTA] reset', + _mail_action: 'quota', + _user: userData._id, + _set: Number(storageUsed) || 0, + _previous_storage_used: Number(updateResponse.value.storageUsed) || 0, + _storage_used: Number(storageUsed) || 0, + _storage_diff: Math.abs((Number(updateResponse.value.storageUsed) || 0) - (Number(storageUsed) || 0)) + }, + ['_previous_storage_used', '_storage_used', '_storage_diff', '_set'] + ); return res.json({ success: true,