diff --git a/packages/logging/src/config/env.config.ts b/packages/logging/src/config/env.config.ts index a36f197bc..14af77c39 100644 --- a/packages/logging/src/config/env.config.ts +++ b/packages/logging/src/config/env.config.ts @@ -6,10 +6,7 @@ dotenv.config(); const envSchema = z.object({ LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace"]).optional().default("info"), - STD_OUT_LOG_FORMAT: z.enum(["json", "pretty"]).optional().default("json"), - FLUENTD_TAG: z.string().optional().default("pino"), - FLUENTD_HOST: z.string().optional(), - FLUENTD_PORT: z.number({ coerce: true }).optional().default(24224), + STD_OUT_LOG_FORMAT: z.enum(["json", "pretty"]).optional().default("json") }); -export const envConfig = envSchema.parse(process.env); \ No newline at end of file +export const envConfig = envSchema.parse(process.env); diff --git a/packages/logging/src/config/index.ts b/packages/logging/src/config/index.ts index 499c583e9..72552ed93 100644 --- a/packages/logging/src/config/index.ts +++ b/packages/logging/src/config/index.ts @@ -1,5 +1,7 @@ -import { envConfig } from "./env.config" +import { envConfig } from "./env.config"; export const config = { ...envConfig -} \ No newline at end of file +}; + +export type Config = typeof config; diff --git a/packages/logging/src/servicies/logger/logger.service.ts b/packages/logging/src/servicies/logger/logger.service.ts index 3efd157fe..6a654d622 100644 --- a/packages/logging/src/servicies/logger/logger.service.ts +++ b/packages/logging/src/servicies/logger/logger.service.ts @@ -3,7 +3,7 @@ import pino from "pino"; import { gcpLogOptions } from "pino-cloud-logging"; import type { PinoPretty } from "pino-pretty"; -import { config } from "../../config"; +import { Config, config as envConfig } from "../../config"; export type Logger = Pick; @@ -16,6 +16,15 @@ interface LoggerOptions extends pino.LoggerOptions { } export class LoggerService implements Logger { + static config: Config = envConfig; + + static configure(config: Partial) { + this.config = { + ...this.config, + ...config + }; + } + static forContext(context: string) { return new LoggerService().setContext(context); } @@ -30,7 +39,7 @@ export class LoggerService implements Logger { private initPino(): pino.Logger { const options: LoggerOptions = { - level: config.LOG_LEVEL, + level: LoggerService.config.LOG_LEVEL, mixin: LoggerService.mixin, timestamp: () => `,"time":"${new Date().toISOString()}"`, ...this.options @@ -46,7 +55,7 @@ export class LoggerService implements Logger { } private getPrettyIfPresent(): PinoPretty.PrettyStream | undefined { - if (typeof window !== "undefined" || config.STD_OUT_LOG_FORMAT !== "pretty") { + if (typeof window !== "undefined" || LoggerService.config.STD_OUT_LOG_FORMAT !== "pretty") { return; }