A Python application we're developing requires a logger. A coworker argues that the logger should be created and configured in every class that's using it. My opinion is that it should be created and configured on application start and passed as a constructor-parameter.
Both variants have their merits and we're unsure what the best practice is.
Not usually; it is typically not meant to be passed as a parameter.
The convention is to use log = logging.getLogger(__name__) in the top of each module. The value of __name__ is different for each module. The resultant value of __name__ can thereby be reflected in each log message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With