chore: Adapt logs to object format (#38204)

chore/log-types-strict
Kevin Aleman 4 months ago committed by GitHub
parent 79f656f00e
commit f65d055f20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      apps/meteor/app/meteor-accounts-saml/server/lib/Utils.ts
  2. 8
      apps/meteor/app/push/server/fcm.ts
  3. 8
      apps/meteor/app/push/server/methods.ts
  4. 6
      apps/meteor/app/utils/lib/templateVarHandler.ts
  5. 6
      apps/meteor/ee/app/livechat-enterprise/server/lib/AutoCloseOnHoldScheduler.ts
  6. 18
      apps/meteor/ee/app/livechat-enterprise/server/lib/AutoTransferChatScheduler.ts
  7. 6
      apps/meteor/ee/app/livechat-enterprise/server/lib/QueueInactivityMonitor.ts
  8. 6
      apps/meteor/ee/app/livechat-enterprise/server/lib/VisitorInactivityMonitor.ts
  9. 12
      apps/meteor/ee/app/livechat-enterprise/server/services/omnichannel.internalService.ts
  10. 2
      apps/meteor/ee/server/lib/ldap/copyCustomFieldsLDAP.ts
  11. 4
      apps/meteor/ee/server/lib/oauth/Manager.ts
  12. 2
      apps/meteor/server/lib/callbacks/callbacksBase.ts
  13. 31
      apps/meteor/server/lib/migrations.ts
  14. 7
      apps/meteor/server/services/calendar/service.ts
  15. 9
      apps/meteor/server/services/calendar/statusEvents/applyStatusChange.ts

@ -154,7 +154,7 @@ export class SAMLUtils {
const buffer = Buffer.from(base64Data, 'base64');
zlib.inflateRaw(buffer, (err, decoded) => {
if (err) {
this.log(`Error while inflating. ${err}`);
this.log({ msg: 'Error while inflating.', err });
return reject(errorCallback(err));
}
@ -426,7 +426,7 @@ export class SAMLUtils {
const attributeList = new Map();
for (const attributeName of userDataMap.attributeList) {
if (profile[attributeName] === undefined) {
this.log(`SAML user profile is missing the attribute ${attributeName}.`);
this.log({ msg: 'SAML user profile is missing the attribute.', attribute: attributeName });
continue;
}
attributeList.set(attributeName, profile[attributeName]);

@ -103,7 +103,7 @@ async function fetchWithRetry(url: string, _removeToken: () => void, options: Ex
}
const error: FCMError = await response.json();
logger.error('sendFCM error', error);
logger.error({ msg: 'sendFCM error', err: error });
return response;
}
@ -164,7 +164,7 @@ export const sendFCM = function ({ userTokens, notification, _removeToken, optio
return;
}
logger.debug('sendFCM', tokens, notification);
logger.debug({ msg: 'sendFCM', tokens, notification });
const messages = getFCMMessagesFromPushData(tokens, notification);
const headers = {
@ -181,7 +181,7 @@ export const sendFCM = function ({ userTokens, notification, _removeToken, optio
const url = `https://fcm.googleapis.com/v1/projects/${options.gcm.projectNumber}/messages:send`;
for (const fcmRequest of messages) {
logger.debug('sendFCM message', fcmRequest);
logger.debug({ msg: 'sendFCM message', request: fcmRequest });
const removeToken = () => {
const { token } = fcmRequest.message;
@ -191,7 +191,7 @@ export const sendFCM = function ({ userTokens, notification, _removeToken, optio
const response = fetchWithRetry(url, removeToken, { method: 'POST', headers, body: JSON.stringify(fcmRequest) });
response.catch((err) => {
logger.error('sendFCM error', err);
logger.error({ msg: 'sendFCM error', err });
});
}
};

@ -100,11 +100,11 @@ export const pushUpdate = async (options: PushUpdateOptions): Promise<Omit<IApps
).deletedCount;
if (removed) {
logger.debug(`Removed ${removed} existing app items`);
logger.debug({ msg: 'Removed existing app items', removed });
}
}
logger.debug('updated', doc);
logger.debug({ msg: 'Push token updated', doc });
// Return the doc we want to use
return doc;
@ -112,7 +112,7 @@ export const pushUpdate = async (options: PushUpdateOptions): Promise<Omit<IApps
Meteor.methods<ServerMethods>({
async 'raix:push-update'(options) {
logger.debug('Got push token from app:', options);
logger.debug({ msg: 'Got push token from app', options });
check(options, {
id: Match.Optional(String),
@ -137,7 +137,7 @@ Meteor.methods<ServerMethods>({
throw new Meteor.Error(403, 'Forbidden access');
}
logger.debug(`Settings userId "${this.userId}" for app:`, id);
logger.debug({ msg: 'Setting userId for app', userId: this.userId, appId: id });
const found = await AppsTokens.updateOne({ _id: id }, { $set: { userId: this.userId } });
return !!found;

@ -9,7 +9,7 @@ export const templateVarHandler = function (variable: string, object: Record<str
if (match == null) {
if (!object.hasOwnProperty(variable)) {
logger?.debug(`user does not have attribute: ${variable}`);
logger?.debug({ msg: 'User does not have attribute', attribute: variable });
return;
}
return object[variable];
@ -20,12 +20,12 @@ export const templateVarHandler = function (variable: string, object: Record<str
const tmplAttrName = match[1];
if (!object.hasOwnProperty(tmplAttrName)) {
logger?.debug(`user does not have attribute: ${tmplAttrName}`);
logger?.debug({ msg: 'User does not have attribute', attribute: tmplAttrName });
return;
}
const attrVal = object[tmplAttrName];
logger?.debug(`replacing template var: ${tmplVar} with value: ${attrVal}`);
logger?.debug({ msg: 'Replacing template var', templateVar: tmplVar, value: attrVal });
tmpVariable = tmpVariable.replace(tmplVar, attrVal);
match = templateRegex.exec(variable);
}

@ -46,7 +46,7 @@ export class AutoCloseOnHoldSchedulerClass {
throw new Error('AutoCloseOnHoldScheduler is not running');
}
this.logger.debug(`Scheduling room ${roomId} to be closed in ${timeout} seconds`);
this.logger.debug({ msg: 'Scheduling room to be closed', roomId, timeoutSeconds: timeout });
await this.unscheduleRoom(roomId);
const jobName = `${SCHEDULER_NAME}-${roomId}`;
@ -60,13 +60,13 @@ export class AutoCloseOnHoldSchedulerClass {
if (!this.running) {
throw new Error('AutoCloseOnHoldScheduler is not running');
}
this.logger.debug(`Unscheduling room ${roomId}`);
this.logger.debug({ msg: 'Unscheduling room', roomId });
const jobName = `${SCHEDULER_NAME}-${roomId}`;
await this.scheduler.cancel({ name: jobName });
}
private async executeJob({ attrs: { data } }: any = {}): Promise<void> {
this.logger.debug(`Executing job for room ${data.roomId}`);
this.logger.debug({ msg: 'Executing job for room', roomId: data.roomId });
const { roomId, comment } = data;
const [room, user] = await Promise.all([LivechatRooms.findOneById(roomId), this.getSchedulerUser()]);

@ -56,7 +56,7 @@ export class AutoTransferChatSchedulerClass {
}
public async scheduleRoom(roomId: string, timeout: number): Promise<void> {
this.logger.debug(`Scheduling room ${roomId} to be transferred in ${timeout} seconds`);
this.logger.debug({ msg: 'Scheduling room to be transferred', roomId, timeoutSeconds: timeout });
await this.unscheduleRoom(roomId);
const jobName = `${SCHEDULER_NAME}-${roomId}`;
@ -69,7 +69,7 @@ export class AutoTransferChatSchedulerClass {
}
public async unscheduleRoom(roomId: string): Promise<void> {
this.logger.debug(`Unscheduling room ${roomId}`);
this.logger.debug({ msg: 'Unscheduling room', roomId });
const jobName = `${SCHEDULER_NAME}-${roomId}`;
await LivechatRooms.unsetAutoTransferOngoingById(roomId);
@ -77,7 +77,7 @@ export class AutoTransferChatSchedulerClass {
}
private async transferRoom(roomId: string): Promise<void> {
this.logger.debug(`Transferring room ${roomId}`);
this.logger.debug({ msg: 'Transferring room', roomId });
const room = await LivechatRooms.findOneById(roomId, {
_id: 1,
v: 1,
@ -97,7 +97,7 @@ export class AutoTransferChatSchedulerClass {
const timeoutDuration = settings.get<number>('Livechat_auto_transfer_chat_timeout').toString();
if (!RoutingManager.getConfig()?.autoAssignAgent) {
this.logger.debug(`Auto-assign agent is disabled, returning room ${roomId} as inquiry`);
this.logger.debug({ msg: 'Auto-assign agent is disabled, returning room as inquiry', roomId });
await returnRoomAsInquiry(room, departmentId, {
scope: 'autoTransferUnansweredChatsToQueue',
@ -109,11 +109,15 @@ export class AutoTransferChatSchedulerClass {
const agent = await RoutingManager.getNextAgent(departmentId, ignoreAgentId);
if (!agent) {
this.logger.error(`No agent found to transfer room ${room._id} which hasn't been answered in ${timeoutDuration} seconds`);
this.logger.error({
msg: 'No agent found to transfer unanswered room',
roomId: room._id,
timeoutSeconds: timeoutDuration,
});
return;
}
this.logger.debug(`Transferring room ${roomId} to agent ${agent.agentId}`);
this.logger.debug({ msg: 'Transferring room to agent', roomId, agentId: agent.agentId });
const transferredBy = await this.getSchedulerUser();
@ -134,7 +138,7 @@ export class AutoTransferChatSchedulerClass {
await Promise.all([LivechatRooms.setAutoTransferredAtById(roomId), this.unscheduleRoom(roomId)]);
} catch (error) {
this.logger.error(`Error while executing job ${SCHEDULER_NAME} for room ${roomId}:`, error);
this.logger.error({ msg: 'Error while executing auto-transfer job', schedulerName: SCHEDULER_NAME, roomId, err: error });
}
}
}

@ -76,7 +76,7 @@ export class OmnichannelQueueInactivityMonitorClass {
async scheduleInquiry(inquiryId: string, time: Date): Promise<void> {
await this.stopInquiry(inquiryId);
this.logger.debug(`Scheduling automatic close of inquiry ${inquiryId} at ${time}`);
this.logger.debug({ msg: 'Scheduling automatic close of inquiry', inquiryId, scheduledAt: time });
const name = this.getName(inquiryId);
this.scheduler.define(name, this.bindedCloseRoom);
@ -118,12 +118,12 @@ export class OmnichannelQueueInactivityMonitorClass {
const room = await LivechatRooms.findOneById(inquiry.rid);
if (!room) {
this.logger.error(`Unable to find room ${inquiry.rid} for inquiry ${inquiryId} to close in queue inactivity monitor`);
this.logger.error({ msg: 'Unable to find room to close in queue inactivity monitor', inquiryId, roomId: inquiry.rid });
return;
}
await Promise.all([this.closeRoomAction(room), this.stopInquiry(inquiryId)]);
this.logger.info(`Closed room ${inquiry.rid} for inquiry ${inquiryId} due to inactivity`);
this.logger.info({ msg: 'Closed room due to queue inactivity', roomId: inquiry.rid, inquiryId });
}
}

@ -98,7 +98,7 @@ export class VisitorInactivityMonitor {
user: this.user,
});
void notifyOnRoomChangedById(room._id);
this.logger.info(`Room ${room._id} closed`);
this.logger.info({ msg: 'Closed room due to visitor inactivity', roomId: room._id });
}
async placeRoomOnHold(room: IOmnichannelRoom) {
@ -128,12 +128,12 @@ export class VisitorInactivityMonitor {
await LivechatRooms.findAbandonedOpenRooms(new Date(), extraQuery).forEach((room) => {
switch (action) {
case 'close': {
this.logger.info(`Closing room ${room._id}`);
this.logger.info({ msg: 'Closing room due to abandoned visitor', roomId: room._id });
promises.push(this.closeRooms(room));
break;
}
case 'on-hold': {
this.logger.info(`Placing room ${room._id} on hold`);
this.logger.info({ msg: 'Placing room on hold due to abandoned visitor', roomId: room._id });
promises.push(this.placeRoomOnHold(room));
break;
}

@ -33,7 +33,7 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE
comment: string,
onHoldBy: Pick<IUser, '_id' | 'username' | 'name'>,
) {
this.logger.debug(`Attempting to place room ${room._id} on hold by user ${onHoldBy?._id}`);
this.logger.debug({ msg: 'Attempting to place room on hold', roomId: room._id, userId: onHoldBy?._id });
const { _id: roomId } = room;
@ -80,7 +80,7 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE
resumeBy: Pick<IUser, '_id' | 'username' | 'name'>,
clientAction = false,
) {
this.logger.debug(`Attempting to resume room ${room._id} on hold by user ${resumeBy?._id}`);
this.logger.debug({ msg: 'Attempting to resume room on hold', roomId: room._id, userId: resumeBy?._id });
if (!room || !isOmnichannelRoom(room)) {
throw new Error('error-invalid-room');
@ -97,13 +97,13 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE
const { _id: roomId, servedBy } = room;
if (!servedBy) {
this.logger.error(`No serving agent found for room ${roomId}`);
this.logger.error({ msg: 'No serving agent found for room', roomId });
throw new Error('error-room-not-served');
}
const inquiry = await LivechatInquiry.findOneByRoomId(roomId, {});
if (!inquiry) {
this.logger.error(`No inquiry found for room ${roomId}`);
this.logger.error({ msg: 'No inquiry found for room', roomId });
throw new Error('error-invalid-inquiry');
}
@ -156,7 +156,7 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE
return;
} catch (e) {
this.logger.error(`Agent ${servingAgent._id} is not available to take the inquiry ${inquiry._id}`, e);
this.logger.error({ msg: 'Agent is not available to take inquiry', agentId: servingAgent._id, inquiryId: inquiry._id, err: e });
if (clientAction) {
// if the action was triggered by the client, we should throw the error
// so the client can handle it and show the error message to the user
@ -182,7 +182,7 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE
room: Pick<IOmnichannelRoom, '_id'>;
inquiry: ILivechatInquiryRecord;
}): Promise<void> {
this.logger.debug(`Attempting to remove current agent from room ${room._id}`);
this.logger.debug({ msg: 'Attempting to remove current agent from room', roomId: room._id });
const { _id: roomId } = room;

@ -56,7 +56,7 @@ export const copyCustomFieldsLDAP = (
Object.entries(map).forEach(([ldapField, userField]) => {
if (!getNestedProp(customFields, userField)) {
logger.debug(`User attribute does not exist: ${userField}`);
logger.debug({ msg: 'User attribute does not exist', userField });
return;
}

@ -22,7 +22,7 @@ export class OAuthEEManager {
const userChannelAdmin = await Users.findOneByUsernameIgnoringCase(channelsAdmin);
if (!userChannelAdmin) {
logger.error(`could not create channel, user not found: ${channelsAdmin}`);
logger.error({ msg: 'could not create channel, user not found', channelsAdmin });
return;
}
@ -38,7 +38,7 @@ export class OAuthEEManager {
if (!room) {
const createdRoom = await createRoom('c', channel, userChannelAdmin, [], false, false);
if (!createdRoom?.rid) {
logger.error(`could not create channel ${channel}`);
logger.error({ msg: 'could not create channel', channel });
return;
}

@ -63,7 +63,7 @@ export class Callbacks<
const wrapCallback =
(callback: Callback<THook>) =>
async (item: unknown, constant?: unknown): Promise<unknown> => {
this.logger?.debug(`Executing callback with id ${callback.id} for hook ${callback.hook}`);
this.logger?.debug({ msg: 'Executing callback', id: callback.id, hook: callback.hook });
return (await this.runOne(callback, item, constant)) ?? item;
};

@ -146,7 +146,12 @@ async function migrate(direction: 'up' | 'down', migration: IMigration): Promise
throw new Error(`Cannot migrate ${direction} on version ${migration.version}`);
}
log.startup(`Running ${direction}() on version ${migration.version}${migration.name ? `(${migration.name})` : ''}`);
log.startup({
msg: 'Running migration',
direction,
version: migration.version,
name: migration.name,
});
await migration[direction]?.(migration);
}
@ -181,9 +186,13 @@ export async function migrateDatabase(targetVersion: 'latest' | number, subcomma
// const { version } = orderedMigrations[orderedMigrations.length - 1];
if (!(await lock())) {
const msg = `Not migrating, control is locked. Attempt ${currentAttempt}/${maxAttempts}`;
if (currentAttempt <= maxAttempts) {
log.warn(`${msg}. Trying again in ${retryInterval} seconds.`);
log.warn({
msg: 'Not migrating, control is locked. Will retry.',
retryIntervalSeconds: retryInterval,
attempt: currentAttempt,
maxAttempts,
});
await sleep(retryInterval * 1000);
@ -212,7 +221,10 @@ export async function migrateDatabase(targetVersion: 'latest' | number, subcomma
}
if (subcommands?.includes('rerun')) {
log.startup(`Rerunning version ${targetVersion}`);
log.startup({
msg: 'Rerunning migration',
targetVersion,
});
const migration = orderedMigrations.find((migration) => migration.version === targetVersion);
if (!migration) {
@ -232,7 +244,10 @@ export async function migrateDatabase(targetVersion: 'latest' | number, subcomma
}
if (currentVersion === version) {
log.startup(`Not migrating, already at version ${version}`);
log.startup({
msg: 'Already at target migration version',
version,
});
unlock(currentVersion);
return true;
}
@ -247,7 +262,11 @@ export async function migrateDatabase(targetVersion: 'latest' | number, subcomma
throw new Error(`Can't find migration version ${version}`);
}
log.startup(`Migrating from version ${orderedMigrations[startIdx].version} -> ${orderedMigrations[endIdx].version}`);
log.startup({
msg: 'Migrating between versions',
fromVersion: orderedMigrations[startIdx].version,
toVersion: orderedMigrations[endIdx].version,
});
try {
const migrations = [];

@ -331,7 +331,12 @@ export class CalendarService extends ServiceClassInternal implements ICalendarSe
status: event.previousStatus,
});
} else {
logger.debug(`Not restoring status for user ${event.uid}: current=${user.status}, stored=${event.previousStatus}`);
logger.debug({
msg: 'Not restoring status for user',
userId: event.uid,
currentStatus: user.status,
previousStatus: event.previousStatus,
});
}
}

@ -20,7 +20,14 @@ export async function applyStatusChange({
status?: UserStatus;
shouldScheduleRemoval?: boolean;
}): Promise<void> {
logger.debug(`Applying status change for event ${eventId} at ${startTime} ${endTime ? `to ${endTime}` : ''} to ${status}`);
logger.debug({
msg: 'Applying status change for event',
eventId,
uid,
startTime,
endTime,
status: status ?? UserStatus.BUSY,
});
const user = await Users.findOneById(uid, { projection: { roles: 1, username: 1, name: 1, status: 1 } });
if (!user || user.status === UserStatus.OFFLINE) {

Loading…
Cancel
Save