chore: improve logs (#12467)

* chore: improve logs

* fix: import

* chore: use safe stringify

* chore: add more logs to google calendar

* chore: use this.log

---------

Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
Udit Takkarandsean-brydon authored and GitHub committed 2023-11-29 19:39:25 +05:30
1 parent 6c4b1154b8
commit 7dc6df2ad6
10 files changed
+53 -20

No files matched your search

@@ -5,6 +5,7 @@ import type z from "zod";
import { ErrorCode } from "@calcom/lib/errorCodes";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
import type { CalendarEvent } from "@calcom/types/Calendar";
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
@@ -87,7 +88,7 @@ export class PaymentService implements IAbstractPaymentService {
}
return paymentData;
} catch (error) {
log.error("Alby: Payment could not be created", bookingId, JSON.stringify(error));
log.error("Alby: Payment could not be created", bookingId, safeStringify(error));
throw new Error(ErrorCode.PaymentCreationFailure);
}
}
@@ -9,6 +9,7 @@ import { getFeatureFlagMap } from "@calcom/features/flags/server/utils";
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
import type CalendarService from "@calcom/lib/CalendarService";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
import type {
Calendar,
@@ -106,6 +107,7 @@ export default class GoogleCalendarService implements Calendar {
});
myGoogleAuth.setCredentials(googleCredentials);
} catch (err) {
this.log.error("Error Refreshing Google Token", safeStringify(err));
let message;
if (err instanceof Error) message = err.message;
else message = String(err);
@@ -251,7 +253,10 @@ export default class GoogleCalendarService implements Calendar {
iCalUID: event.data.iCalUID,
};
} catch (error) {
console.error("There was an error contacting google calendar service: ", error);
this.log.error(
"There was an error creating event in google calendar: ",
safeStringify({ error, selectedCalendar, credentialId })
);
throw error;
}
}
@@ -332,7 +337,10 @@ export default class GoogleCalendarService implements Calendar {
}
return evt?.data;
} catch (error) {
console.error("There was an error contacting google calendar service: ", error);
this.log.error(
"There was an error updating event in google calendar: ",
safeStringify({ error, event, uid })
);
throw error;
}
}
@@ -354,6 +362,10 @@ export default class GoogleCalendarService implements Calendar {
});
return event?.data;
} catch (error) {
this.log.error(
"There was an error deleting event from google calendar: ",
safeStringify({ error, event, externalCalendarId })
);
const err = error as GoogleCalError;
/**
* 410 is when an event is already deleted on the Google cal before on cal.com
@@ -502,7 +514,10 @@ export default class GoogleCalendarService implements Calendar {
return busyData;
}
} catch (error) {
this.log.error("There was an error contacting google calendar service: ", error);
this.log.error(
"There was an error getting availability from google calendar: ",
safeStringify({ error, selectedCalendars })
);
throw error;
}
}
@@ -524,7 +539,7 @@ export default class GoogleCalendarService implements Calendar {
} satisfies IntegrationCalendar)
);
} catch (error) {
this.log.error("There was an error contacting google calendar service: ", error);
this.log.error("There was an error getting calendars: ", safeStringify(error));
throw error;
}
}
@@ -6,6 +6,7 @@ import Paypal from "@calcom/app-store/paypal/lib/Paypal";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { ErrorCode } from "@calcom/lib/errorCodes";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
import type { CalendarEvent } from "@calcom/types/Calendar";
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
@@ -91,7 +92,7 @@ export class PaymentService implements IAbstractPaymentService {
}
return paymentData;
} catch (error) {
log.error("Paypal: Payment could not be created for bookingId", bookingId);
log.error("Paypal: Payment could not be created for bookingId", bookingId, safeStringify(error));
throw new Error(ErrorCode.PaymentCreationFailure);
}
}
@@ -170,7 +171,11 @@ export class PaymentService implements IAbstractPaymentService {
}
return paymentData;
} catch (error) {
log.error("Paypal: Payment method could not be collected for bookingId", bookingId);
log.error(
"Paypal: Payment method could not be collected for bookingId",
bookingId,
safeStringify(error)
);
throw new Error("Paypal: Payment method could not be collected");
}
}
@@ -7,6 +7,7 @@ import { sendAwaitingPaymentEmail } from "@calcom/emails";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { getErrorFromUnknown } from "@calcom/lib/errors";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
import type { CalendarEvent } from "@calcom/types/Calendar";
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
@@ -132,8 +133,7 @@ export class PaymentService implements IAbstractPaymentService {
}
return paymentData;
} catch (error) {
console.error(`Payment could not be created for bookingId ${bookingId}`, error);
log.error("Stripe: Payment could not be created", bookingId, JSON.stringify(error));
log.error("Stripe: Payment could not be created", bookingId, safeStringify(error));
throw new Error("payment_not_created_error");
}
}
@@ -207,7 +207,7 @@ export class PaymentService implements IAbstractPaymentService {
log.error(
"Stripe: Payment method could not be collected for bookingId",
bookingId,
JSON.stringify(error)
safeStringify(error)
);
throw new Error("Stripe: Payment method could not be collected");
}
@@ -286,7 +286,7 @@ export class PaymentService implements IAbstractPaymentService {
return paymentData;
} catch (error) {
log.error("Stripe: Could not charge card for payment", _bookingId, JSON.stringify(error));
log.error("Stripe: Could not charge card for payment", _bookingId, safeStringify(error));
throw new Error(ErrorCode.ChargeCardFailure);
}
}
@@ -378,7 +378,7 @@ export class PaymentService implements IAbstractPaymentService {
await this.stripe.paymentIntents.cancel(payment.externalId, { stripeAccount });
return true;
} catch (e) {
log.error("Stripe: Unable to delete Payment in stripe of paymentId", paymentId, JSON.stringify(e));
log.error("Stripe: Unable to delete Payment in stripe of paymentId", paymentId, safeStringify(e));
return false;
}
}