Skip to content

Commit f837394

Browse files
authored
chore: Adapt logs to object format - 2 (RocketChat#38001)
1 parent e3fe764 commit f837394

16 files changed

Lines changed: 184 additions & 81 deletions

File tree

apps/meteor/app/integrations/server/lib/ScriptEngine.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ export abstract class IntegrationScriptEngine<IsIncoming extends boolean> {
276276
}
277277

278278
if (!script[method]) {
279-
this.logger.error(`Method "${method}" not found in the Integration "${integration.name}"`);
279+
this.logger.error({
280+
msg: 'Script method not found in the Integration',
281+
method,
282+
integration: integration.name,
283+
});
280284
await updateHistory({ historyId, step: `execute-script-no-method-${method}` });
281285
return;
282286
}
@@ -327,12 +331,20 @@ export abstract class IntegrationScriptEngine<IsIncoming extends boolean> {
327331
}
328332

329333
const script = await wrapExceptions(() => this.getIntegrationScript(integration)).catch((e) => {
330-
this.logger.error(e);
334+
this.logger.error({
335+
msg: 'Error getting Integration script',
336+
integration: integration.name,
337+
err: e,
338+
});
331339
throw e;
332340
});
333341

334342
if (!script[method]) {
335-
this.logger.error(`Method "${method}" not found in the Integration "${integration.name}"`);
343+
this.logger.error({
344+
msg: 'Script method not found in the Integration',
345+
method,
346+
integration: integration.name,
347+
});
336348
return;
337349
}
338350

apps/meteor/app/lib/server/functions/getFullUserData.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ settings.watch<string>('Accounts_CustomFields', (settingValue) => {
6060
customFields[`customFields.${key}`] = 1;
6161
});
6262
} catch (e) {
63-
logger.warn(`The JSON specified for "Accounts_CustomFields" is invalid. The following error was thrown: ${e}`);
63+
logger.warn({
64+
msg: 'The JSON specified for "Accounts_CustomFields" is invalid. The following error was thrown',
65+
err: e,
66+
});
6467
}
6568
});
6669

apps/meteor/app/lib/server/lib/deprecationWarningLogger.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const apiDeprecationLogger = ((logger) => {
4141

4242
metrics.deprecations.inc({ type: 'deprecation', kind: 'endpoint', name: endpoint });
4343

44-
logger.warn(message);
44+
logger.warn({ msg: message, endpoint, version, info });
4545
},
4646
parameter: (
4747
endpoint: string,
@@ -66,7 +66,7 @@ export const apiDeprecationLogger = ((logger) => {
6666

6767
writeDeprecationHeader(res, 'parameter-deprecation', message, version);
6868

69-
logger.warn(message);
69+
logger.warn({ msg: message, endpoint, parameter, version });
7070
},
7171

7272
deprecatedParameterUsage: (
@@ -95,7 +95,7 @@ export const apiDeprecationLogger = ((logger) => {
9595

9696
writeDeprecationHeader(res, 'invalid-usage', message, version);
9797

98-
logger.warn(message);
98+
logger.warn({ msg: message, endpoint, parameter, version });
9999
},
100100
};
101101
})(deprecationLogger.section('API'));
@@ -114,7 +114,7 @@ export const methodDeprecationLogger = ((logger) => {
114114
}
115115
compareVersions(version, message);
116116
metrics.deprecations.inc({ type: 'deprecation', name: method, kind: 'method' });
117-
logger.warn(message);
117+
logger.warn({ msg: message, method, version, replacement });
118118
},
119119
parameter: (method: string, parameter: string, version: DeprecationLoggerNextPlannedVersion) => {
120120
const message = `The parameter "${parameter}" in the method "${method}" is deprecated and will be removed on version ${version}`;
@@ -125,7 +125,7 @@ export const methodDeprecationLogger = ((logger) => {
125125
metrics.deprecations.inc({ type: 'parameter-deprecation', name: method, params: parameter });
126126

127127
compareVersions(version, message);
128-
logger.warn(message);
128+
logger.warn({ msg: message, method, parameter, version });
129129
},
130130
deprecatedParameterUsage: (
131131
method: string,
@@ -150,7 +150,7 @@ export const methodDeprecationLogger = ((logger) => {
150150

151151
metrics.deprecations.inc({ type: 'invalid-usage', name: method, params: parameter, kind: 'method' });
152152

153-
logger.warn(message);
153+
logger.warn({ msg: message, method, parameter, version });
154154
},
155155
/** @deprecated */
156156
warn: (message: string) => {
@@ -159,7 +159,7 @@ export const methodDeprecationLogger = ((logger) => {
159159
}
160160

161161
compareVersions('0.0.0', message);
162-
logger.warn(message);
162+
logger.warn({ msg: message });
163163
},
164164
};
165165
})(deprecationLogger.section('METHOD'));

apps/meteor/app/livechat/server/api/v1/room.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ const livechatRoomsEndpoints = API.v1
516516
body: isPOSTLivechatRoomsCloseAll,
517517
},
518518
async function action() {
519-
livechatLogger.info(`User ${this.userId} is removing all closed rooms`);
519+
livechatLogger.info({ msg: 'User is removing all closed rooms', userId: this.userId });
520520

521521
const params = this.bodyParams;
522522

@@ -527,7 +527,7 @@ const livechatRoomsEndpoints = API.v1
527527
});
528528
await Promise.all(promises);
529529

530-
livechatLogger.info(`User ${this.userId} removed ${promises.length} closed rooms`);
530+
livechatLogger.info({ msg: 'User removed closed rooms', userId: this.userId, removedRooms: promises.length });
531531
return API.v1.success({ removedRooms: promises.length });
532532
},
533533
);

apps/meteor/app/livechat/server/api/v1/visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ API.v1.addRoute('livechat/visitor/:token', {
151151
},
152152
});
153153
} catch (e) {
154-
livechatLogger.error(e);
154+
livechatLogger.error({ msg: 'Error removing visitor', err: e });
155155
throw new Meteor.Error('error-removing-visitor', 'An error ocurred while deleting visitor');
156156
}
157157
},

apps/meteor/app/livechat/server/api/v1/webhooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ API.v1.addRoute(
7272
}
7373

7474
try {
75-
logger.debug(`Testing webhook ${webhookUrl}`);
75+
logger.debug({ msg: 'Testing webhook', webhookUrl });
7676
const request = await fetch(webhookUrl, options);
7777
const response = await request.text();
7878

79-
logger.debug({ response });
79+
logger.debug({ msg: 'Webhook response', response });
8080
if (request.status === 200) {
8181
return API.v1.success();
8282
}
8383

8484
throw new Error('Invalid status code');
8585
} catch (error) {
86-
logger.error(`Error testing webhook: ${error}`);
86+
logger.error({ msg: 'Error testing webhook', err: error });
8787
throw new Error('error-invalid-webhook-response');
8888
}
8989
},

apps/meteor/app/livechat/server/business-hour/BusinessHourManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class BusinessHourManager {
287287
const failed = result.filter((r) => r.status === 'rejected');
288288
if (failed.length > 0) {
289289
failed.forEach((error: any) => {
290-
businessHourLogger.error('Failed to update business hours with new timezone', error.reason);
290+
businessHourLogger.error({ msg: 'Failed to update business hours with new timezone', err: error });
291291
});
292292
}
293293

apps/meteor/app/livechat/server/business-hour/Single.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export class SingleBusinessHourBehavior extends AbstractBusinessHourBehavior imp
3030
async onNewAgentCreated(agentId: string): Promise<void> {
3131
const defaultBusinessHour = await LivechatBusinessHours.findOneDefaultBusinessHour();
3232
if (!defaultBusinessHour) {
33-
businessHourLogger.debug('No default business hour found for agentId', {
33+
businessHourLogger.debug({
34+
msg: 'No default business hour found for agentId',
3435
agentId,
3536
});
3637
return;

0 commit comments

Comments
 (0)