From 93be70ee787e63bbcd2b2f1b51a2495810dbcd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Sat, 28 Dec 2024 10:34:42 +0000 Subject: [PATCH] Create root logger only if necessary --- src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 25824b8..eca87f1 100644 --- a/src/index.js +++ b/src/index.js @@ -50,9 +50,14 @@ const setRootLogger = logger => { */ const debino = (namespace, { prefix = 'sub', suffix = 'component', ...options } = {}) => { - const { loggers, rootLogger } = global[globalSymbol]; + let { loggers, rootLogger } = global[globalSymbol]; let childLogger = loggers.get(namespace); + // Ensure the root logger is set. + if (!rootLogger) { + rootLogger = global[globalSymbol].rootLogger = pino(); + } + // Create the logger for this namespace if it doesn't exist. if (!childLogger) { const bindings = createBindings(namespace, prefix, suffix); @@ -77,7 +82,7 @@ const debino = (namespace, { prefix = 'sub', suffix = 'component', ...options } global[globalSymbol] = { loggers: new Map(), - rootLogger: pino() + rootLogger: null }; /**