I have a Go main-application that uses a custom log
package and a custom config
package.
This application "consumes" other packages that they need more logging or config parameters. Perhaps, a useful example is a custom api-package
:
debug|info|warning
logs (the errors are managed as usual by the caller, in this case, the main-application).I see three solutions to solve this problem:
log
and config
) from the main object to the sub-package when the package is "initialised", then it will use this pointer like the main-application.log
or config
) directly into the sub-package too, but this could raise concurrency issues between the main-application's instance vs. the package's instance.At the moment I use method 1, am I doing it right? What is the Go conventions about this? Are there other ways to solve this?
EDIT
Just to explain, why it is not a duplicate of the proposed "duplicated" questions:
logging
(writing "somewhere") and not for config
(reading and writing). No other options are taken in consideration, for example which one follow at best the standards, which one is more performant,...logging
and the config
in one "application" (or in goroutines).If you mark as duplicate, please just explain why. So I can see if this is a really duplicate or if my question was misunderstand.