-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should logger fail if there's an error #9
Comments
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 |
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 |
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…
|
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 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?
The text was updated successfully, but these errors were encountered: