useid / handlersjs

MIT License
3 stars 3 forks source link

When multiple packages depend on handlersjs-logging, loggerFactory is not set properly #216

Closed lem-onade closed 9 months ago

lem-onade commented 1 year ago

We're having the following problem:

package A makes use of handlersjs-logging. The logger factory is set properly, getLoggerFor works. No issues here. package A also uses package B, which contains some shared handlers. These handlers contain a protected readonly logger = getLoggerFor(this, 5, 5)

Some handlers in package A extend the handlers from package B.

When trying to initiate one of the handlers in package A, the following error is thrown somewhere in package B:

(node:28192) UnhandledPromiseRejectionWarning: Error: No LoggerFactory was set to create loggers.

The problem is not only with these handlers, but with any class that makes use of getLoggerFor that is part of a dependency of package A.


It seems the logger and loggerFactory variables in handlersjs-logging's main.ts do not share the same value as package A when handlersjs-logging is used in dependencies of this package.

https://github.com/digita-ai/handlersjs/blob/1bd5e29b3b82378b3aef6bb3fd8034d46f7abf6c/packages/handlersjs-logging/lib/main.ts#L5-L6

Which causes the error on line 40 to be thrown for these dependencies.

https://github.com/digita-ai/handlersjs/blob/1bd5e29b3b82378b3aef6bb3fd8034d46f7abf6c/packages/handlersjs-logging/lib/main.ts#L38-L42


I'm wondering whether changing the logger and loggerFactory variables to be global variables would fix this issue.

Open to other ideas and suggestions.

AbelVandenBriel commented 1 year ago

I fixed this issue by calling setLoggerFactory(new ConsoleLoggerFactory()) in package B.

woutermont commented 1 year ago

Is that a clean, permanent fix? If further discussion is necessary, lets plan a short one Wednesday before or after the meetings.