Skip to content

Commit

Permalink
Create root logger only if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor committed Dec 28, 2024
1 parent faa5cf7 commit 93be70e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -77,7 +82,7 @@ const debino = (namespace, { prefix = 'sub', suffix = 'component', ...options }

global[globalSymbol] = {
loggers: new Map(),
rootLogger: pino()
rootLogger: null
};

/**
Expand Down

0 comments on commit 93be70e

Please sign in to comment.