Open nofun97 opened 4 years ago
I don't think it should return error but failing silently can be problematic. Maybe it should just log a warning if there's no logger. Or should it add a standard logger when there's no logger?
Currently, the library will panic when trying to log or get a logger and when it fails to apply a configuration. https://github.com/anz-bank/pkg/blob/master/log/util.go#L23-L56
I am in favour of not panicking if the logger is not on the context. A default logger could be used when one is missing on the context.
This will allow code to transition to using this package a bit easier. Thinking tactically, for example, if there's some crucial logging that needs to be done but passing context all the way down into to that line of code would require a large refactoring.
Defaults should cover most use cases, and not write a warnings. However, if it's important to let the developer know they should configure a logger manually, I would be in favour of adding a special value to the log line produced, something like unconfigured_logger=true
or context=default_logger
.
Okay, what about during applying a configuration to a logger? We're trying to let user make their own configuration, to handle that, we have the function func Apply(logger Logger) error
and currently if would panic if Apply
fails.
Agreed, logging should generally not fail. Serving traffic is more important that getting the logs. Monitoring can generate alerts when there's a step change in logging volume. So…
Apply
: logging functions shouldn't impact traffic.If this library automagically creates and starts using a default-configuration-logger if there isnt a logger in a context, i think it needs offer an API that lets the programmer look inside a context to see if it contains a logger or not. Is there already a way of doing that? I can see there is a func From(ctx context.Context) Logger
, but it creates a default logger and doesnt give the caller a way to tell which logger they got -- one that was in the input ctx or a new one.
e.g. in a variety of situations when i am trying to configure and wire my app together properly, i want to make sure i am using my special logger instance with custom configuration. if i dont have that exact logger in a context i want to be able to detect it and fail as it indicates a programming error.
In https://github.com/anz-bank/pkg/blob/master/log/util.go#L17 the library will panic if logger isn't created yet. Should the library fail or not?