diff --git a/environment.d.ts b/environment.d.ts index f5efa40..000a0b4 100644 --- a/environment.d.ts +++ b/environment.d.ts @@ -2,11 +2,13 @@ import { PrismaClient } from "@prisma/client"; import { Client as LDAPClient } from "ldapts"; import { ApolloClient, InMemoryCache } from "@apollo/client"; import { LLDAPAuthResponse } from "@/ldap"; +import { Logger } from "pino"; declare global { var prisma: PrismaClient | undefined; var ldapClient: LDAPClient | undefined; var authResponse: LLDAPAuthResponse | undefined; + var logger: Logger; namespace NodeJS { interface ProcessEnv { diff --git a/src/logger.ts b/src/logger.ts index 14f4f9a..4664ece 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,7 +1,9 @@ import pino from "pino"; -const logger = pino(); +if (global.logger == null) { + global.logger = pino(); +} export function getLogger(name: string) { - return logger.child({ name }); + return global.logger.child({ name }); }