feat: adds configurable logging (#4914)

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
This commit is contained in:
Piyush Gupta
2025-03-21 18:39:13 +05:30
committed by GitHub
parent 7dd5cf8b6e
commit 5527f184b7
150 changed files with 1167 additions and 292 deletions
@@ -11,6 +11,7 @@ import {
deleteS3FilesByEnvironmentId,
} from "@formbricks/lib/storage/service";
import { validateInputs } from "@formbricks/lib/utils/validate";
import { logger } from "@formbricks/logger";
import { ZId, ZString } from "@formbricks/types/common";
import { DatabaseError, InvalidInputError, ValidationError } from "@formbricks/types/errors";
import { TProject, TProjectUpdateInput, ZProject, ZProjectUpdateInput } from "@formbricks/types/project";
@@ -79,7 +80,7 @@ export const updateProject = async (
return project;
} catch (error) {
if (error instanceof z.ZodError) {
console.error(JSON.stringify(error.errors, null, 2));
logger.error(error.errors, "Error updating project");
}
throw new ValidationError("Data validation of project failed");
}
@@ -174,7 +175,7 @@ export const deleteProject = async (projectId: string): Promise<TProject> => {
await Promise.all(s3FilesPromises);
} catch (err) {
// fail silently because we don't want to throw an error if the files are not deleted
console.error(err);
logger.error(err, "Error deleting S3 files");
}
} else {
const localFilesPromises = project.environments.map(async (environment) => {
@@ -185,7 +186,7 @@ export const deleteProject = async (projectId: string): Promise<TProject> => {
await Promise.all(localFilesPromises);
} catch (err) {
// fail silently because we don't want to throw an error if the files are not deleted
console.error(err);
logger.error(err, "Error deleting local files");
}
}
@@ -5,6 +5,7 @@ import { prisma } from "@formbricks/database";
import { cache } from "@formbricks/lib/cache";
import { projectCache } from "@formbricks/lib/project/cache";
import { validateInputs } from "@formbricks/lib/utils/validate";
import { logger } from "@formbricks/logger";
import { DatabaseError } from "@formbricks/types/errors";
export const getProjectByEnvironmentId = reactCache(
@@ -29,7 +30,7 @@ export const getProjectByEnvironmentId = reactCache(
return projectPrisma;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
console.error(error);
logger.error(error, "Error fetching project by environment id");
throw new DatabaseError(error.message);
}
throw error;