Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should a Python logger be passed as parameter? [closed]

Tags:

python

logging

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.

like image 989
Anonymous Coward Avatar asked Aug 09 '26 20:08

Anonymous Coward


1 Answers

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.

like image 195
Asclepius Avatar answered Aug 11 '26 09:08

Asclepius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!