fx
fx copied to clipboard
Provide a user-controlled logger to the container for foundation modules to consume.
Fx applications may provide a fx.Printer with the fx.Logger option. Typical Fx applications include a logging module that provides something more powerful than a fx.Printer, such as a Zap logger. However, if this logging module has a dependency on other modules (eg Zap cores), then these lower level modules have no method available to them outside of log
and fmt
. These are not good substitutes as it sidesteps the application author's control of stdout and stderr (eg fx.NopLogger).
One solution is to provide the fx.Printer type to modules, but it has drawbacks (possible multiple logger choices, resolving type collision if an application also fx.Provides an fx.Printer, etc).
The main reason for that is that the typical logger inside a typical application requires configuration to set itself up properly. Configuration loading is part of the lifecycle managed by Fx, thus chicken and egg between logger and config.