Skip to content

Commit

Permalink
Remove unnecesary logs from functions without recent failures or crit…
Browse files Browse the repository at this point in the history
…ical paths
  • Loading branch information
KevLehman committed Sep 7, 2023
1 parent cf59c8a commit 86eb3a2
Show file tree
Hide file tree
Showing 46 changed files with 44 additions and 295 deletions.
2 changes: 0 additions & 2 deletions apps/meteor/app/api/server/v1/voip/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ API.v1.addRoute(
}

try {
logger.debug(`Setting extension ${extension} for agent with id ${user._id}`);
await Users.setExtension(user._id, extension);
return API.v1.success();
} catch (e) {
Expand Down Expand Up @@ -146,7 +145,6 @@ API.v1.addRoute(
return API.v1.notFound();
}
if (!user.extension) {
logger.debug(`User ${user._id} is not associated with any extension. Skipping`);
return API.v1.success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import moment from 'moment';
import { closeBusinessHour } from '../../../../ee/app/livechat-enterprise/server/business-hour/Helper';
import { callbacks } from '../../../../lib/callbacks';
import { settings } from '../../../settings/server';
import { businessHourLogger } from '../lib/logger';
import type { IBusinessHourBehavior, IBusinessHourType } from './AbstractBusinessHour';

export class BusinessHourManager {
Expand All @@ -27,7 +26,6 @@ export class BusinessHourManager {

async startManager(): Promise<void> {
await this.createCronJobsForWorkHours();
businessHourLogger.debug('Cron jobs created, setting up callbacks');
this.setupCallbacks();
await this.cleanupDisabledDepartmentReferences();
await this.behavior.onStartBusinessHours();
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/business-hour/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const openBusinessHourDefault = async (): Promise<void> => {
await Users.makeAgentsWithinBusinessHourAvailable();
}
await Users.updateLivechatStatusBasedOnBusinessHours();
businessHourLogger.debug('Done opening default business hours');
};

export const createDefaultBusinessHourIfNotExists = async (): Promise<void> => {
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/livechat/server/business-hour/Single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { filterBusinessHoursThatMustBeOpened, openBusinessHourDefault } from './

export class SingleBusinessHourBehavior extends AbstractBusinessHourBehavior implements IBusinessHourBehavior {
async openBusinessHoursByDayAndHour(): Promise<void> {
businessHourLogger.debug('opening single business hour');
return openBusinessHourDefault();
}

Expand All @@ -23,7 +22,6 @@ export class SingleBusinessHourBehavior extends AbstractBusinessHourBehavior imp
}

async onStartBusinessHours(): Promise<void> {
businessHourLogger.debug('Starting Single Business Hours');
return openBusinessHourDefault();
}

Expand Down
6 changes: 0 additions & 6 deletions apps/meteor/app/livechat/server/hooks/afterUserActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Users } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { Livechat } from '../lib/Livechat';
import { callbackLogger } from '../lib/logger';

type IAfterSaveUserProps = {
user: IUser;
Expand Down Expand Up @@ -34,17 +33,12 @@ const handleAgentCreated = async (user: IUser) => {

const handleDeactivateUser = async (user: IUser) => {
if (wasAgent(user)) {
callbackLogger.debug({
msg: 'Removing agent extension & making agent unavailable',
userId: user._id,
});
await Users.makeAgentUnavailableAndUnsetExtension(user._id);
}
};

const handleActivateUser = async (user: IUser) => {
if (isAgent(user)) {
callbackLogger.debug('Adding agent', user._id);
await Livechat.addAgent(user.username);
}
};
Expand Down
4 changes: 0 additions & 4 deletions apps/meteor/app/livechat/server/hooks/saveAnalyticsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { LivechatRooms } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { normalizeMessageFileUpload } from '../../../utils/server/functions/normalizeMessageFileUpload';
import { callbackLogger } from '../lib/logger';

callbacks.add(
'afterSaveMessage',
Expand All @@ -13,7 +12,6 @@ callbacks.add(
return message;
}

callbackLogger.debug(`Calculating Omnichannel metrics for room ${room._id}`);
// skips this callback if the message was edited
if (!message || isEditedMessage(message)) {
return message;
Expand Down Expand Up @@ -43,7 +41,6 @@ callbacks.add(
const isResponseTotal = room.metrics?.response?.total;

if (agentLastReply === room.ts) {
callbackLogger.debug('Calculating: first message from agent');
// first response
const firstResponseDate = now;
const firstResponseTime = (now.getTime() - new Date(visitorLastQuery).getTime()) / 1000;
Expand All @@ -66,7 +63,6 @@ callbacks.add(
reactionTime,
};
} else if (visitorLastQuery > agentLastReply) {
callbackLogger.debug('Calculating: visitor sent a message after agent');
// response, not first
const responseTime = (now.getTime() - new Date(visitorLastQuery).getTime()) / 1000;
const avgResponseTime =
Expand Down
6 changes: 0 additions & 6 deletions apps/meteor/app/livechat/server/lib/Analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export const Analytics = {
const from = moment.tz(fDate, 'YYYY-MM-DD', timezone).startOf('day').utc();
const to = moment.tz(tDate, 'YYYY-MM-DD', timezone).endOf('day').utc();

logger.debug(`getAgentOverviewData[${name}] -> Using timezone ${timezone} with date range ${from} - ${to}`);

if (!(moment(from).isValid() && moment(to).isValid())) {
logger.error('livechat:getAgentOverviewData => Invalid dates');
return;
Expand Down Expand Up @@ -79,8 +77,6 @@ export const Analytics = {
const to = moment.tz(tDate, 'YYYY-MM-DD', timezone).endOf('day').utc();
const isSameDay = from.diff(to, 'days') === 0;

logger.debug(`getAnalyticsChartData[${name}] -> Using timezone ${timezone} with date range ${from} - ${to}`);

if (!(moment(from).isValid() && moment(to).isValid())) {
logger.error('livechat:getAnalyticsChartData => Invalid dates');
return;
Expand Down Expand Up @@ -133,8 +129,6 @@ export const Analytics = {
const from = moment.tz(fDate, 'YYYY-MM-DD', timezone).startOf('day').utc();
const to = moment.tz(tDate, 'YYYY-MM-DD', timezone).endOf('day').utc();

logger.debug(`getAnalyticsOverviewData[${name}] -> Using timezone ${timezone} with date range ${from} - ${to}`);

if (!(moment(from).isValid() && moment(to).isValid())) {
logger.error('livechat:getAnalyticsOverviewData => Invalid dates');
return;
Expand Down
5 changes: 0 additions & 5 deletions apps/meteor/app/livechat/server/lib/Departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ class DepartmentHelperClass {

const department = await LivechatDepartment.findOneById(departmentId);
if (!department) {
this.logger.debug(`Department not found: ${departmentId}`);
throw new Error('error-department-not-found');
}

const { _id } = department;

const ret = await LivechatDepartment.removeById(_id);
if (ret.acknowledged !== true) {
this.logger.error(`Department record not removed: ${_id}. Result from db: ${ret}`);
throw new Error('error-failed-to-delete-department');
}
this.logger.debug(`Department record removed: ${_id}`);

const agentsIds: string[] = await LivechatDepartmentAgents.findAgentsByDepartmentId<Pick<ILivechatDepartmentAgents, 'agentId'>>(
department._id,
Expand All @@ -47,8 +44,6 @@ class DepartmentHelperClass {
}
});

this.logger.debug(`Post-department-removal actions completed: ${_id}. Notifying callbacks with department and agentsIds`);

setImmediate(() => {
void callbacks.run('livechat.afterRemoveDepartment', { department, agentsIds });
});
Expand Down
9 changes: 0 additions & 9 deletions apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const queueInquiry = async (inquiry: ILivechatInquiryRecord, defaultAgent
const dbInquiry = await LivechatInquiry.findOneById(inquiry._id);

if (!dbInquiry) {
logger.error(`Inquiry with id ${inquiry._id} not found`);
throw new Error('inquiry-not-found');
}

Expand Down Expand Up @@ -68,7 +67,6 @@ export const QueueManager: queueManager = {
);

if (!(await checkServiceStatus({ guest, agent }))) {
logger.debug(`Cannot create room for visitor ${guest._id}. No online agents`);
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}

Expand Down Expand Up @@ -96,8 +94,6 @@ export const QueueManager: queueManager = {
throw new Error('inquiry-not-found');
}

logger.debug(`Generated inquiry for visitor ${guest._id} with id ${inquiry._id} [Not queued]`);

await LivechatRooms.updateRoomCount();

await queueInquiry(inquiry, agent);
Expand All @@ -114,7 +110,6 @@ export const QueueManager: queueManager = {

async unarchiveRoom(archivedRoom) {
if (!archivedRoom) {
logger.error('No room to unarchive');
throw new Error('no-room-to-unarchive');
}

Expand Down Expand Up @@ -145,17 +140,13 @@ export const QueueManager: queueManager = {
await LivechatRooms.unarchiveOneById(rid);
const room = await LivechatRooms.findOneById(rid);
if (!room) {
logger.debug(`Room with id ${rid} not found`);
throw new Error('room-not-found');
}
const inquiry = await LivechatInquiry.findOneById(await createLivechatInquiry({ rid, name, guest, message, extraData: { source } }));
if (!inquiry) {
logger.error(`Inquiry for visitor ${guest._id} not found`);
throw new Error('inquiry-not-found');
}

logger.debug(`Generated inquiry for visitor ${v._id} with id ${inquiry._id} [Not queued]`);

await queueInquiry(inquiry, defaultAgent);
logger.debug(`Inquiry ${inquiry._id} queued`);

Expand Down
8 changes: 2 additions & 6 deletions apps/meteor/app/livechat/server/lib/RoutingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const RoutingManager: Routing = {
},

async setMethodNameAndStartQueue(name) {
logger.debug(`Changing default routing method from ${this.methodName} to ${name}`);
logger.info(`Changing default routing method from ${this.methodName} to ${name}`);
if (!this.methods[name]) {
logger.warn(`Cannot change routing method to ${name}. Selected Routing method does not exists. Defaulting to Manual_Selection`);
this.methodName = 'Manual_Selection';
Expand All @@ -87,7 +87,6 @@ export const RoutingManager: Routing = {

// eslint-disable-next-line @typescript-eslint/naming-convention
registerMethod(name, Method) {
logger.debug(`Registering new routing method with name ${name}`);
this.methods[name] = new Method();
},

Expand Down Expand Up @@ -188,7 +187,6 @@ export const RoutingManager: Routing = {
const { servedBy } = room;

if (servedBy) {
logger.debug(`Unassigning current agent for inquiry ${inquiry._id}`);
await LivechatRooms.removeAgentByRoomId(rid);
await this.removeAllRoomSubscriptions(room);
await dispatchAgentDelegated(rid);
Expand Down Expand Up @@ -254,15 +252,14 @@ export const RoutingManager: Routing = {

await LivechatInquiry.takeInquiry(_id);
const inq = await this.assignAgent(inquiry as InquiryWithAgentInfo, agent);
logger.debug(`Inquiry ${inquiry._id} taken by agent ${agent.agentId}`);
logger.info(`Inquiry ${inquiry._id} taken by agent ${agent.agentId}`);

callbacks.runAsync('livechat.afterTakeInquiry', inq, agent);

return LivechatRooms.findOneById(rid);
},

async transferRoom(room, guest, transferData) {
logger.debug(`Transfering room ${room._id} by ${transferData.transferredBy._id}`);
if (transferData.departmentId) {
logger.debug(`Transfering room ${room._id} to department ${transferData.departmentId}`);
return forwardRoomToDepartment(room, guest, transferData);
Expand All @@ -278,7 +275,6 @@ export const RoutingManager: Routing = {
},

async delegateAgent(agent, inquiry) {
logger.debug(`Delegating Inquiry ${inquiry._id}`);
const defaultAgent = await callbacks.run('livechat.beforeDelegateAgent', agent, {
department: inquiry?.department,
});
Expand Down
13 changes: 3 additions & 10 deletions apps/meteor/app/livechat/server/sendMessageBySMS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,27 @@ import { callbackLogger } from './lib/logger';
callbacks.add(
'afterSaveMessage',
async (message, room) => {
callbackLogger.debug('Attempting to send SMS message');
// skips this callback if the message was edited
if (isEditedMessage(message)) {
callbackLogger.debug('Message was edited, skipping SMS send');
return message;
}

if (!settings.get('SMS_Enabled')) {
callbackLogger.debug('SMS is not enabled, skipping SMS send');
return message;
}

// only send the sms by SMS if it is a livechat room with SMS set to true
if (!(isOmnichannelRoom(room) && room.sms && room.v && room.v.token)) {
callbackLogger.debug('Room is not a livechat room, skipping SMS send');
return message;
}

// if the message has a token, it was sent from the visitor, so ignore it
if (message.token) {
callbackLogger.debug('Message was sent from the visitor, skipping SMS send');
return message;
}

// if the message has a type means it is a special message (like the closing comment), so skips
if (message.t) {
callbackLogger.debug('Message is a special message, skipping SMS send');
return message;
}

Expand All @@ -52,8 +46,9 @@ callbacks.add(
const { location } = message;
extraData = Object.assign({}, extraData, { location });
}
const service = settings.get<string>('SMS_Service');

const SMSService = await OmnichannelIntegration.getSmsService(settings.get('SMS_Service'));
const SMSService = await OmnichannelIntegration.getSmsService(service);

if (!SMSService) {
callbackLogger.debug('SMS Service is not configured, skipping SMS send');
Expand All @@ -63,14 +58,12 @@ callbacks.add(
const visitor = await LivechatVisitors.getVisitorByToken(room.v.token, { projection: { phone: 1 } });

if (!visitor?.phone || visitor.phone.length === 0) {
callbackLogger.debug('Visitor does not have a phone number, skipping SMS send');
return message;
}

try {
callbackLogger.debug(`Message will be sent to ${visitor.phone[0].phoneNumber} through service ${settings.get('SMS_Service')}`);
await SMSService.send(room.sms.from, visitor.phone[0].phoneNumber, message.msg, extraData);
callbackLogger.debug(`SMS message sent to ${visitor.phone[0].phoneNumber}`);
callbackLogger.debug(`SMS message sent to ${visitor.phone[0].phoneNumber} via ${service}`);
} catch (e) {
callbackLogger.error(e);
}
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/app/livechat/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ Meteor.startup(async () => {
await createDefaultBusinessHourIfNotExists();

settings.watch<boolean>('Livechat_enable_business_hours', async (value) => {
Livechat.logger.debug(`Changing business hour type to ${value}`);
Livechat.logger.info(`Changing business hour type to ${value}`);
if (value) {
await businessHourManager.startManager();
Livechat.logger.debug(`Business hour manager started`);
return;
}
await businessHourManager.stopManager();
Livechat.logger.debug(`Business hour manager stopped`);
});

settings.watch<string>('Livechat_Routing_Method', (value) => {
Expand Down
Loading

0 comments on commit 86eb3a2

Please sign in to comment.