From da5373ef25b5175ec79d22c651c5c48c223d4d70 Mon Sep 17 00:00:00 2001 From: NotNite Date: Fri, 28 Apr 2023 12:07:44 -0400 Subject: [PATCH] make logger a global --- environment.d.ts | 2 ++ src/logger.ts | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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 }); }