Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/meteor/app/search/server/events/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { searchProviderService } from '../service';
export class EventService {
_pushError(name: string, value: string, _payload?: unknown) {
// TODO implement a (performant) cache
SearchLogger.debug(`Error on event '${name}' with id '${value}'`);
SearchLogger.debug({
msg: 'Error on event',
eventName: name,
eventId: value,
});
}

promoteEvent(name: string, value: string, payload?: unknown) {
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/app/search/server/model/SearchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export abstract class SearchProvider<TPayload = any> {
throw new Error(`cannot instantiate provider: ${key} does not match key-pattern`);
}

SearchLogger.info(`create search provider ${key}`);
SearchLogger.info({
msg: 'create search provider',
providerKey: key,
});

this._key = key;
this._settings = new Settings(key);
Expand Down
10 changes: 8 additions & 2 deletions apps/meteor/app/search/server/service/SearchProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ export class SearchProviderService {

if (this.activeProvider) {
const provider = this.activeProvider;
SearchLogger.debug(`Stopping provider '${provider.key}'`);
SearchLogger.debug({
msg: 'Stopping provider',
providerKey: provider.key,
});

await new Promise<void>((resolve) => provider.stop(resolve));
}

this.activeProvider = undefined;

SearchLogger.debug(`Start provider '${id}'`);
SearchLogger.debug({
msg: 'Start provider',
providerKey: id,
});

await this.providers[id].run(reason);
this.activeProvider = this.providers[id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export class SearchResultValidationService {
const subscription = await this.getSubscription(msg.rid, uid);

if (subscription) {
SearchLogger.debug(`user ${uid} can access ${msg.rid}`);
SearchLogger.debug({
msg: 'User can access message',
userId: uid,
roomId: msg.rid,
});
return {
...msg,
user: msg.u._id,
Expand All @@ -59,7 +63,11 @@ export class SearchResultValidationService {
};
}

SearchLogger.debug(`user ${uid} can NOT access ${msg.rid}`);
SearchLogger.debug({
msg: 'User cannot access message',
userId: uid,
roomId: msg.rid,
});
return undefined;
}),
)
Expand All @@ -74,11 +82,19 @@ export class SearchResultValidationService {
const subscription = await this.getSubscription(room._id, uid);

if (!subscription) {
SearchLogger.debug(`user ${uid} can NOT access ${room._id}`);
SearchLogger.debug({
msg: 'User cannot access room',
userId: uid,
roomId: room._id,
});
return undefined;
}

SearchLogger.debug(`user ${uid} can access ${room._id}`);
SearchLogger.debug({
msg: 'User can access room',
userId: uid,
roomId: room._id,
});

return {
...room,
Expand Down
12 changes: 10 additions & 2 deletions apps/meteor/ee/app/livechat-enterprise/server/api/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ API.v1.addRoute(
visitor,
block: true,
});
logger.info(`Visitor with id ${visitor.visitorId} blocked by user with id ${user._id}`);
logger.info({
msg: 'Visitor blocked',
visitorId: visitor.visitorId,
userId: user._id,
});

await closeBlockedRoom(visitor, user);

Expand All @@ -82,7 +86,11 @@ API.v1.addRoute(
visitor,
block: false,
});
logger.info(`Visitor with id ${visitor.visitorId} unblocked by user with id ${user._id}`);
logger.info({
msg: 'Visitor unblocked',
visitorId: visitor.visitorId,
userId: user._id,
});

return API.v1.success();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ export const getDepartmentsWhichUserCanAccess = async (userId: string, includeDi
export const hasAccessToDepartment = async (userId: string, departmentId: string): Promise<boolean> => {
const department = await LivechatDepartmentAgents.findOneByAgentIdAndDepartmentId(userId, departmentId, { projection: { _id: 1 } });
if (department) {
helperLogger.debug(`User ${userId} has access to department ${departmentId} because they are an agent`);
helperLogger.debug({
msg: 'User has access to department as agent',
userId,
departmentId,
});
return true;
}

const monitorAccess = await LivechatDepartment.checkIfMonitorIsMonitoringDepartmentById(userId, departmentId);
helperLogger.debug(
`User ${userId} ${monitorAccess ? 'has' : 'does not have'} access to department ${departmentId} because they are a monitor`,
);
helperLogger.debug({
msg: 'User monitor access status for department',
userId,
departmentId,
hasAccess: monitorAccess,
});
return monitorAccess;
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ callbacks.add(
return options;
}

cbLogger.debug(`Updating department ${newDepartmentId} ancestors for room ${rid}`);
cbLogger.debug({
msg: 'Updating department ancestors for room',
departmentId: newDepartmentId,
roomId: rid,
});
await LivechatRooms.updateDepartmentAncestorsById(room._id, ancestors);

return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class VisitorInactivityMonitor {
{ projection: { _id: 1, abandonedRoomsCloseCustomMessage: 1 } },
);
if (!department) {
this.logger.error(`Department ${departmentId} not found`);
this.logger.error({ msg: 'Department not found', departmentId });
return;
}
this.messageCache.set(department._id, department.abandonedRoomsCloseCustomMessage);
Expand Down Expand Up @@ -145,7 +145,7 @@ export class VisitorInactivityMonitor {
const errors = result.filter(isPromiseRejectedResult).map((r) => r.reason);

if (errors.length) {
this.logger.error({ msg: `Error while removing priority from ${errors.length} rooms`, reason: errors[0] });
this.logger.error({ msg: 'Error while removing priority from rooms', count: errors.length, reason: errors[0] });
}

this._initializeMessageCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export const requestPdfTranscript = async (
return;
}

logger.info(`Queuing work for room ${room._id}`);
logger.info({ msg: 'Queuing work for room', roomId: room._id });
await QueueWorker.queueWork('work', `${serviceName}.workOnPdf`, details);
};
6 changes: 3 additions & 3 deletions apps/meteor/ee/app/livechat-enterprise/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ Meteor.startup(async () => {
await updatePredictedVisitorAbandonment();
});
settings.change<string>('Livechat_business_hour_type', async (value) => {
logger.debug(`Changing business hour type to ${value}`);
logger.debug({ msg: 'Changing business hour type', value });
if (!Object.keys(businessHours).includes(value)) {
logger.error(`Invalid business hour type ${value}`);
logger.error({ msg: 'Invalid business hour type', value });
return;
}
businessHourManager.registerBusinessHourBehavior(businessHours[value as keyof typeof businessHours]);
if (settings.get('Livechat_enable_business_hours')) {
await businessHourManager.restartManager();
logger.debug(`Business hour manager started`);
logger.debug('Business hour manager started');
}
});
});
8 changes: 4 additions & 4 deletions apps/meteor/ee/server/lib/ldap/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class LDAPEEManager extends LDAPManager {
await this.syncUserChannels(ldap, user, dn);
await this.syncUserTeams(ldap, user, dn, isNewRecord);
} catch (e) {
logger.debug(`Advanced Sync failed for user: ${dn}`);
logger.debug({ msg: 'Advanced Sync failed for user', dn });
logger.error(e);
Comment thread
KevLehman marked this conversation as resolved.
Outdated
}
}
Expand Down Expand Up @@ -264,9 +264,9 @@ export class LDAPEEManager extends LDAPManager {
const result = await ldap.searchRaw(baseDN, searchOptions);

if (!Array.isArray(result) || result.length === 0) {
logger.debug(`${username} is not in ${groupName} group!!!`);
logger.debug({ msg: 'User is not in group', username, groupName });
} else {
logger.debug(`${username} is in ${groupName} group.`);
logger.debug({ msg: 'User is in group', username, groupName });
return true;
}

Expand Down Expand Up @@ -465,7 +465,7 @@ export class LDAPEEManager extends LDAPManager {
const subscription = await SubscriptionsRaw.findOneByRoomIdAndUserId(room._id, user._id);
if (subscription) {
await removeUserFromRoom(room._id, user);
logger.debug(`Removed user ${username} from channel ${room._id}`);
logger.debug({ msg: 'Removed user from channel', username, roomId: room._id });
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/server/features/EmailInbox/EmailInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function configureEmailInboxes(): Promise<void> {

for await (const emailInboxRecord of emailInboxesCursor) {
try {
logger.info(`Setting up email interceptor for ${emailInboxRecord.email}`);
logger.info({ msg: 'Setting up email interceptor', email: emailInboxRecord.email });

const imap = new IMAPInterceptor(
{
Expand Down Expand Up @@ -84,11 +84,11 @@ export async function configureEmailInboxes(): Promise<void> {

inboxes.set(emailInboxRecord.email, { imap, smtp, config: emailInboxRecord });
} catch (err) {
logger.error({ msg: `Error setting up email interceptor for ${emailInboxRecord.email}`, err });
logger.error({ msg: 'Error setting up email interceptor', email: emailInboxRecord.email, err });
}
}

logger.info(`Configured a total of ${inboxes.size} inboxes`);
logger.info({ msg: 'Configured a total of inboxes', count: inboxes.size });
}

Meteor.startup(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function uploadAttachment(attachmentParam: Attachment, rid: string, visito
}

export async function onEmailReceived(email: ParsedMail, inbox: string, department = ''): Promise<void> {
logger.info(`New email conversation received on inbox ${inbox}. Will be assigned to department ${department}`);
logger.info({ msg: 'New email conversation received on inbox. Will be assigned to department', inbox, department });
if (!email.from?.value?.[0]?.address) {
return;
}
Expand All @@ -112,7 +112,7 @@ export async function onEmailReceived(email: ParsedMail, inbox: string, departme
const guest = await getGuestByEmail(email.from.value[0].address, email.from.value[0].name, department);

if (!guest) {
logger.error(`No visitor found for ${email.from.value[0].address}`);
logger.error({ msg: 'No visitor found', address: email.from.value[0].address });
return;
}

Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/server/lib/cas/createNewUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createNewUser = async (username: string, { attributes, casVersion,
};

// Create the user
logger.debug(`User "${username}" does not exist yet, creating it`);
logger.debug({ msg: 'User does not exist yet, creating it', username });
const userId = await Accounts.insertUserDoc({}, newUser);

// Fetch and use it
Expand All @@ -44,9 +44,9 @@ export const createNewUser = async (username: string, { attributes, casVersion,
throw new Error('Unexpected error: Unable to find user after its creation.');
}

logger.debug(`Created new user for '${username}' with id: ${user._id}`);
logger.debug({ msg: 'Created new user', username, userId: user._id });

logger.debug(`Joining user to attribute channels: ${attributes.rooms}`);
logger.debug({ msg: 'Joining user to attribute channels', rooms: attributes.rooms });
if (attributes.rooms) {
const roomNames = attributes.rooms.split(',');
for await (const roomName of roomNames) {
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/server/lib/cas/loginHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ export const loginHandlerCAS = async (options: any): Promise<undefined | Account

if (source !== replacedValue) {
internalAttributes[internalName] = replacedValue;
logger.debug(`Sourced internal attribute: ${internalName} = ${replacedValue}`);
logger.debug({ msg: 'Sourced internal attribute', internalName, value: replacedValue });
} else {
logger.debug(`Sourced internal attribute: ${internalName} skipped.`);
logger.debug({ msg: 'Sourced internal attribute skipped', internalName });
}
}
}

// Search existing user by its external service id
logger.debug(`Looking up user by id: ${username}`);
logger.debug({ msg: 'Looking up user by id', username });
// First, look for a user that has logged in from CAS with this username before
const user = await findExistingCASUser(username);

if (user) {
logger.debug(`Using existing user for '${username}' with id: ${user._id}`);
logger.debug({ msg: 'Using existing user', username, userId: user._id });
if (syncEnabled) {
logger.debug('Syncing user attributes');
// Update name
Expand All @@ -107,7 +107,7 @@ export const loginHandlerCAS = async (options: any): Promise<undefined | Account

if (!userCreationEnabled) {
// Should fail as no user exist and can't be created
logger.debug(`User "${username}" does not exist yet, will fail as no user creation is enabled`);
logger.debug({ msg: 'User does not exist yet, will fail as no user creation is enabled', username });
throw new Meteor.Error(Accounts.LoginCancelledError.numericError, 'no matching user account found');
}

Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/server/lib/cas/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const casTicket = function (req: IncomingMessageWithUrl, token: string, callback
const baseUrl = settings.get<string>('CAS_base_url');
const version = parseFloat(settings.get('CAS_version') ?? '1.0') as 1.0 | 2.0;
const appUrl = Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
logger.debug(`Using CAS_base_url: ${baseUrl}`);
logger.debug({ msg: 'Using CAS_base_url', baseUrl });

validate(
{
Expand All @@ -41,9 +41,9 @@ const casTicket = function (req: IncomingMessageWithUrl, token: string, callback
ticketId,
async (err, status, username, details) => {
if (err) {
logger.error(`error when trying to validate: ${err.message}`);
logger.error({ msg: 'error when trying to validate', err });
} else if (status) {
logger.info(`Validated user: ${username}`);
logger.info({ msg: 'Validated user', username });
const userInfo: Partial<ICredentialToken['userInfo']> = { username: username as string };

// CAS 2.0 attributes handling
Expand All @@ -52,7 +52,7 @@ const casTicket = function (req: IncomingMessageWithUrl, token: string, callback
}
await CredentialTokens.create(token, userInfo);
} else {
logger.error(`Unable to validate ticket: ${ticketId}`);
logger.error({ msg: 'Unable to validate ticket', ticketId });
}
// logger.debug("Received response: " + JSON.stringify(details, null , 4));

Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/server/lib/ldap/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ export class LDAPConnection {
});

res.on('end', () => {
searchLogger.info(`LDAP Search found ${realEntries} entries and loaded the data of ${entries.length}.`);
searchLogger.info({
msg: 'LDAP search completed',
foundEntries: realEntries,
loadedEntries: entries.length,
});
resolve(entries);
});
});
Expand Down
Loading
Loading