make logger a global

This commit is contained in:
Julian 2023-04-28 12:07:44 -04:00
parent 967bb2a2d2
commit da5373ef25
Signed by: NotNite
GPG Key ID: BD91A5402CCEB08A
2 changed files with 6 additions and 2 deletions

2
environment.d.ts vendored
View File

@ -2,11 +2,13 @@ import { PrismaClient } from "@prisma/client";
import { Client as LDAPClient } from "ldapts"; import { Client as LDAPClient } from "ldapts";
import { ApolloClient, InMemoryCache } from "@apollo/client"; import { ApolloClient, InMemoryCache } from "@apollo/client";
import { LLDAPAuthResponse } from "@/ldap"; import { LLDAPAuthResponse } from "@/ldap";
import { Logger } from "pino";
declare global { declare global {
var prisma: PrismaClient | undefined; var prisma: PrismaClient | undefined;
var ldapClient: LDAPClient | undefined; var ldapClient: LDAPClient | undefined;
var authResponse: LLDAPAuthResponse | undefined; var authResponse: LLDAPAuthResponse | undefined;
var logger: Logger;
namespace NodeJS { namespace NodeJS {
interface ProcessEnv { interface ProcessEnv {

View File

@ -1,7 +1,9 @@
import pino from "pino"; import pino from "pino";
const logger = pino(); if (global.logger == null) {
global.logger = pino();
}
export function getLogger(name: string) { export function getLogger(name: string) {
return logger.child({ name }); return global.logger.child({ name });
} }