fix: Add critical logger for booking created log to prevent stdout buffering issues (#24570)

* Add critical logger for booking created log to prevent stdout buffering issues

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* Add comment

* Separate critialLogger into it's own file

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-10-28 12:59:44 -03:00
1 parent 51d78e6f9d
commit d7df154059
9 files changed
+39 -14

No files matched your search

+2 -2
View File
@@ -313,7 +313,7 @@ export default function Signup({
id="gtm-init-script"
// It is strictly not necessary to disable, but in a future update of react/no-danger this will error.
// And we don't want it to error here anyways
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `(function (w, d, s, l, i) {
w[l] = w[l] || []; w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
@@ -323,7 +323,7 @@ export default function Signup({
}}
/>
<noscript
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `<iframe src="https://www.googletagmanager.com/ns.html?id=${process.env.NEXT_PUBLIC_GTM_ID}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`,
}}
@@ -193,9 +193,9 @@ test.describe("Organization:", () => {
});
await expect(page.getByTestId("success-page")).toBeVisible();
// All the teammates should be in the booking
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await expect(page.getByText(user1.name!, { exact: true })).toBeVisible();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await expect(page.getByText(user2.name!, { exact: true })).toBeVisible();
}
);
+3 -3
View File
@@ -4,7 +4,7 @@ import { createHash } from "crypto";
import EventEmitter from "events";
import type { IncomingMessage, ServerResponse } from "http";
import { createServer } from "http";
// eslint-disable-next-line no-restricted-imports
import type { Messages } from "mailhog";
import { totp } from "otplib";
import { v4 as uuid } from "uuid";
@@ -213,7 +213,7 @@ export async function setupManagedEvent({
addManagedEventToTeamMates: true,
managedEventUnlockedFields: unlockedFields,
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const memberUser = users.get().find((u) => u.name === teamMateName)!;
const { team } = await adminUser.getFirstTeamMembership();
const managedEvent = await adminUser.getFirstTeamEvent(team.id, SchedulingType.MANAGED);
@@ -365,7 +365,7 @@ async function createUserWithSeatedEvent(users: Fixtures["users"]) {
},
],
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const eventType = user.eventTypes.find((e) => e.slug === slug)!;
return { user, eventType };
}
@@ -184,7 +184,7 @@ test.describe("Bookings", () => {
// Anyone of the teammates could be the Host of the booking.
const chosenUser = await page.getByTestId("booking-host-name").textContent();
expect(chosenUser).not.toBeNull();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(teamMatesObj.concat([{ name: owner.name! }]).some(({ name }) => name === chosenUser)).toBe(
true
);
@@ -248,7 +248,7 @@ test.describe("Bookings", () => {
// Anyone of the teammates could be the Host of the booking.
const chosenUser = await page.getByTestId("booking-host-name").textContent();
expect(chosenUser).not.toBeNull();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(teamMatesObj.concat([{ name: owner.name! }]).some(({ name }) => name === chosenUser)).toBe(
true
);
@@ -90,7 +90,7 @@ test.describe("Organization", () => {
// This test is already covered by booking.e2e.ts where existing user is invited and his booking links are tested.
// We can re-test here when we want to test some more scenarios.
// eslint-disable-next-line @typescript-eslint/no-empty-function
test("existing user invited to an organization", () => {});
test("nonexisting user invited to a Team inside organization", async ({
@@ -313,7 +313,7 @@ test.describe("Organization", () => {
await page.locator('[data-testid="continue-with-email-button"]').click();
await expect(page.locator('[data-testid="signup-submit-button"]')).toBeVisible();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await page.locator('input[name="username"]').fill(existingUser.username!);
await page
.locator('input[name="email"]')
@@ -67,6 +67,7 @@ import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
import { HttpError } from "@calcom/lib/http-error";
import logger from "@calcom/lib/logger";
import { criticalLogger } from "@calcom/lib/logger.server";
import { getPiiFreeCalendarEvent, getPiiFreeEventType } from "@calcom/lib/piiFreeData";
import { safeStringify } from "@calcom/lib/safeStringify";
import { getTranslation } from "@calcom/lib/server/i18n";
@@ -1726,7 +1727,7 @@ async function handler(
await usersRepository.updateLastActiveAt(booking.userId);
const organizerUserAvailability = availableUsers.find((user) => user.id === booking?.userId);
logger.info(`Booking created`, {
criticalLogger.info(`Booking created`, {
bookingUid: booking.uid,
selectedCalendarIds: organizerUser.allSelectedCalendars?.map((c) => c.id) ?? [],
availabilitySnapshot: organizerUserAvailability?.availabilityData
@@ -149,7 +149,7 @@ const Locations: React.FC<LocationsProps> = ({
);
useEffect(() => {
if (!!prefillLocation) {
if (prefillLocation) {
const newLocationType = prefillLocation.value;
const canAppendLocation = !validLocations.find((location) => location.type === newLocationType);
+24
View File
@@ -0,0 +1,24 @@
import fs from "fs";
import logger from "./logger";
/** This should be used if we want to ensure a log statement is always executed.
*
* This should only be used server side
*/
export const criticalLogger = logger.getSubLogger({
name: "critical",
overwrite: {
transportJSON: (logObj) => {
const logString = JSON.stringify(logObj);
const buffer = Buffer.from(logString + "\n");
try {
fs.writeSync(process.stdout.fd, buffer);
} catch (error) {
console.log(`Critical logger: Failed to write log using fs.writeSync: ${error}`);
console.log(logString);
}
},
},
});
@@ -219,7 +219,7 @@ export function SelectWithValidation<
position: "absolute",
}}
value={hiddenInputValue}
// eslint-disable-next-line @typescript-eslint/no-empty-function
onChange={() => {}}
// TODO:Not able to get focus to work
// onFocus={() => selectRef.current?.focus()}