mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-26 02:32:26 +01:00
Trim logs sent to loggly (#15503)
* try making missing x-client header errors smaller * add server emoji as tag * always truncate headers
This commit is contained in:
@@ -24,6 +24,22 @@ const _config = {
|
||||
|
||||
export { _config as _loggerConfig }; // exported for use during tests
|
||||
|
||||
const slimLogs = winston.format(info => {
|
||||
if (info && info.message && info.message.indexOf('BadRequest: Missing x-client headers') === 0) {
|
||||
info.body = undefined;
|
||||
info.message = 'BadRequest: Missing x-client headers';
|
||||
}
|
||||
if (info && info.message && info.message.indexOf('TooManyRequests') === 0) {
|
||||
info.message = 'TooManyRequests';
|
||||
}
|
||||
info.headers = {
|
||||
'x-api-user': info.headers['x-api-user'] || 'unknown',
|
||||
'x-client': info.headers['x-client'] || 'unknown',
|
||||
'user-agent': info.headers['user-agent'] || 'unknown',
|
||||
};
|
||||
return info;
|
||||
});
|
||||
|
||||
if (IS_PROD) {
|
||||
if (ENABLE_CONSOLE_LOGS_IN_PROD) {
|
||||
logger
|
||||
@@ -44,11 +60,20 @@ if (IS_PROD) {
|
||||
}
|
||||
|
||||
if (LOGGLY_TOKEN && LOGGLY_SUBDOMAIN) {
|
||||
const tags = ['Winston-NodeJS'];
|
||||
if (nconf.get('SERVER_EMOJI')) {
|
||||
tags.push(nconf.get('SERVER_EMOJI'));
|
||||
}
|
||||
logger.add(new Loggly({
|
||||
inputToken: LOGGLY_TOKEN,
|
||||
subdomain: LOGGLY_SUBDOMAIN,
|
||||
tags: ['Winston-NodeJS'],
|
||||
tags,
|
||||
json: true,
|
||||
format: winston.format.combine(
|
||||
slimLogs(),
|
||||
winston.format.timestamp(),
|
||||
winston.format.json(),
|
||||
),
|
||||
}));
|
||||
}
|
||||
// Do not log anything when testing unless specified
|
||||
|
||||
Reference in New Issue
Block a user