diff --git a/src/lib/logging.ts b/src/lib/logging.ts index 0d9b57d..3b22fb2 100644 --- a/src/lib/logging.ts +++ b/src/lib/logging.ts @@ -1,12 +1,18 @@ import pino from 'pino'; +/** + * workaround to provide IntelliSense hints https://stackoverflow.com/a/61048124 + */ +export type LoggingLevel = pino.LevelWithSilent | (string & {}); + interface InitLoggerOptions { appName: string; devMode: boolean; destination?: pino.DestinationStream; + level?: LoggingLevel; } -export function initLogger({appName, devMode, destination}: InitLoggerOptions) { +export function initLogger({appName, devMode, destination, level = 'debug'}: InitLoggerOptions) { const transportConfig = devMode ? { target: 'pino-pretty', @@ -18,10 +24,10 @@ export function initLogger({appName, devMode, destination}: InitLoggerOptions) { } : undefined; - const options = { + const options: pino.LoggerOptions = { name: appName, safe: true, - leve: 'debug', + level, serializers: { error: pino.stdSerializers.err, }, diff --git a/src/nodekit.ts b/src/nodekit.ts index fceced0..5267b06 100644 --- a/src/nodekit.ts +++ b/src/nodekit.ts @@ -61,12 +61,14 @@ export class NodeKit { appInstallation, appEnv, appDevMode, + appLoggingLevel: process.env.APP_LOGGING_LEVEL || fileConfig.appLoggingLevel, }); this.logger = initLogger({ appName: this.config.appName as string, devMode: appDevMode, destination: this.config.appLoggingDestination, + level: this.config.appLoggingLevel, }); const redactSensitiveQueryParams = prepareSensitiveQueryParamsRedacter( diff --git a/src/types.ts b/src/types.ts index 86b2af4..f5dfa88 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ -import {pino} from 'pino'; +import type {pino} from 'pino'; +import type {LoggingLevel} from './lib/logging'; export interface AppConfig { appName?: string; @@ -20,6 +21,7 @@ export interface AppConfig { appSensitiveQueryParams?: string[]; appLoggingDestination?: pino.DestinationStream; + appLoggingLevel?: LoggingLevel; appTracingEnabled?: boolean; appTracingServiceName?: string;