Emit logging events from packages.
External packages don't know if
logger that may exists on the global level is reasonably defined. To solve this
PackageLogger defines a common subset of logging levels which when invoked emit
log events. Package's user are then free to listen to these events and pass them to their logger.
const PackageLogger = ;const logger = PackageLogger; // We never assign this `logger` to `global` as that would overwrite application's `global.logger` if such exists.// ...logger; // This will emit `log` event. For users to listen to it logger needs to be exported from the package (see next example)// Export the logger so that package's users can use it.modulesexportslogger = logger;
Forwarding log events in the application:
const myPackage = ;// This now forwards log events from my-package to Winston.myPackagelogger