chore: add granular logging to the logger (#16734)
* Update README.md * Update README.md * Update README.md * Update README.md * Update turbo.json * Update trpc-provider.tsx * Update logger.ts * update prisma index * Update trpc.ts * Update trpc-provider.tsx * Update trpc.ts * Update .env.example * Update logger.ts
This commit is contained in:
1 parent
e0922c5ee0
commit
c4a1382982
7 files changed
+48
-7
No files matched your search
@@ -3,7 +3,7 @@ import { Logger } from "tslog";
|
||||
import { IS_PRODUCTION } from "./constants";
|
||||
|
||||
const logger = new Logger({
|
||||
minLevel: !!process.env.NEXT_PUBLIC_DEBUG ? 2 : 4,
|
||||
minLevel: parseInt(process.env.NEXT_PUBLIC_LOGGER_LEVEL ?? "4"),
|
||||
maskValuesOfKeys: ["password", "passwordConfirmation", "credentials", "credential"],
|
||||
prettyLogTimeZone: IS_PRODUCTION ? "UTC" : "local",
|
||||
prettyErrorStackTemplate: " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}", // default
|
||||
|
||||
@@ -15,7 +15,26 @@ const globalForPrisma = global as unknown as {
|
||||
prismaWithClientExtensions: PrismaClientWithExtensions;
|
||||
};
|
||||
|
||||
if (!!process.env.NEXT_PUBLIC_DEBUG) prismaOptions.log = ["query", "error", "warn"];
|
||||
const loggerLevel = parseInt(process.env.NEXT_PUBLIC_LOGGER_LEVEL ?? "", 10);
|
||||
|
||||
if (!isNaN(loggerLevel)) {
|
||||
switch (loggerLevel) {
|
||||
case 5:
|
||||
case 6:
|
||||
prismaOptions.log = ["error"];
|
||||
break;
|
||||
case 4:
|
||||
prismaOptions.log = ["warn", "error"];
|
||||
break;
|
||||
case 3:
|
||||
prismaOptions.log = ["info", "error", "warn"];
|
||||
break;
|
||||
default:
|
||||
// For values 0, 1, 2 (or anything else below 3)
|
||||
prismaOptions.log = ["query", "info", "error", "warn"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevents flooding with idle connections
|
||||
const prismaWithoutClientExtensions =
|
||||
|
||||
@@ -73,7 +73,7 @@ export const trpc: CreateTRPCNext<AppRouter, NextPageContext, null> = createTRPC
|
||||
// adds pretty logs to your console in development and logs errors in production
|
||||
loggerLink({
|
||||
enabled: (opts) =>
|
||||
!!process.env.NEXT_PUBLIC_DEBUG || (opts.direction === "down" && opts.result instanceof Error),
|
||||
(typeof process.env.NEXT_PUBLIC_LOGGER_LEVEL === 'number' && process.env.NEXT_PUBLIC_LOGGER_LEVEL >= 0) || (opts.direction === "down" && opts.result instanceof Error),
|
||||
}),
|
||||
splitLink({
|
||||
// check for context property `skipBatch`
|
||||
|
||||
Reference in new issue
Block a user