diff --git a/yarn-project/foundation/src/log/pino-logger.ts b/yarn-project/foundation/src/log/pino-logger.ts index 98b92f5fa39..d0a840a1cac 100644 --- a/yarn-project/foundation/src/log/pino-logger.ts +++ b/yarn-project/foundation/src/log/pino-logger.ts @@ -64,6 +64,15 @@ function isLevelEnabled(logger: pino.Logger<'verbose', boolean>, level: LogLevel const defaultLogLevel = process.env.NODE_ENV === 'test' ? 'silent' : 'info'; const [logLevel, logFilters] = parseEnv(process.env.LOG_LEVEL, defaultLogLevel); +// Define custom logging levels for pino. +const customLevels = { verbose: 25 }; +const pinoOpts = { customLevels, useOnlyCustomLevels: false, level: logLevel }; + +export const levels = { + labels: { ...pino.levels.labels, ...Object.fromEntries(Object.entries(customLevels).map(e => e.reverse())) }, + values: { ...pino.levels.values, ...customLevels }, +}; + // Transport options for pretty logging to stderr via pino-pretty. const useColor = true; const { bold, reset } = createColors({ useColor }); @@ -79,24 +88,17 @@ export const pinoPrettyOpts = { singleLine: !['1', 'true'].includes(process.env.LOG_MULTILINE ?? ''), }; -const prettyTransport: pino.TransportSingleOptions = { +const prettyTransport: pino.TransportTargetOptions = { target: 'pino-pretty', options: pinoPrettyOpts, + level: 'trace', }; // Transport for vanilla stdio logging as JSON. -const stdioTransport: pino.TransportSingleOptions = { +const stdioTransport: pino.TransportTargetOptions = { target: 'pino/file', options: { destination: 2 }, -}; - -// Define custom logging levels for pino. -const customLevels = { verbose: 25 }; -const pinoOpts = { customLevels, useOnlyCustomLevels: false, level: logLevel }; - -export const levels = { - labels: { ...pino.levels.labels, ...Object.fromEntries(Object.entries(customLevels).map(e => e.reverse())) }, - values: { ...pino.levels.values, ...customLevels }, + level: 'trace', }; // Transport for OpenTelemetry logging. While defining this here is an abstraction leakage since this @@ -107,9 +109,10 @@ export const levels = { // since pino will load this transport separately on a worker thread, to minimize disruption to the main loop. const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT; const otelOpts = { levels }; -const otelTransport: pino.TransportSingleOptions = { +const otelTransport: pino.TransportTargetOptions = { target: '@aztec/telemetry-client/otel-pino-stream', options: otelOpts, + level: 'trace', }; function makeLogger() { @@ -128,7 +131,7 @@ function makeLogger() { ['1', 'true', 'TRUE'].includes(process.env.LOG_JSON ?? '') ? stdioTransport : prettyTransport, otlpEndpoint ? otelTransport : undefined, ]); - return pino(pinoOpts, pino.transport({ targets })); + return pino(pinoOpts, pino.transport({ targets, levels: levels.values })); } }