diff --git a/index.test.ts b/index.test.ts index 76ccbcc..52f0123 100644 --- a/index.test.ts +++ b/index.test.ts @@ -1,10 +1,10 @@ import { - getLogger, addHandler, + getLogger, LogData, LogLevel, removeHandler, - removeAllHandlers, + removeHandlers, replaceHandlers } from './index' @@ -98,7 +98,7 @@ test('adding and removing handlers', () => { log.info('') expect(events.length).toBe(8) - removeAllHandlers() + removeHandlers() log.info('') expect(events.length).toBe(8) diff --git a/index.ts b/index.ts index 9f6558b..d4cf7ae 100644 --- a/index.ts +++ b/index.ts @@ -85,7 +85,7 @@ export function removeHandler(handler?: LogHandler) { /** * Remove all handlers. */ -export function removeAllHandlers() { +export function removeHandlers() { process.removeAllListeners(LOG_EVENT_NAME) } @@ -97,7 +97,7 @@ export function removeAllHandlers() { * to the console. */ export function replaceHandlers(handler: LogHandler) { - removeAllHandlers() + removeHandlers() addHandler(handler) } @@ -139,8 +139,9 @@ export function defaultHandler(data: LogData) { console.error(entry) } -// Always enable the default handler -addHandler(defaultHandler) +// Enable the default handler if there no other handler +// already enabled e.g. by another package using `logga` +if (!process.listenerCount(LOG_EVENT_NAME)) addHandler(defaultHandler) /** * Get a logger for the specific application or package.