logging: getLogger() or getLogger(__name__)?
Laurent Pointal
laurent.pointal at free.fr
Wed Jul 27 12:50:06 EDT 2016
Malcolm Greene wrote:
> I've read that best practice for logging is to place the following line
> at the top of all modules:
>
> logger = getLogger(__name__)
>
> I'm curious why the following technique wouldn't be a better choice:
>
> logger = getLogger()
>
> Are there scenarios that favor one style over another?
With __name__ you will have one logger per source file (module), with
corresponding filtering possibilities, and organized hierarchically as are
packages (logging use . to built its loggers hierarchy).
Without __name__, you have one global default logger.
>
> Thank you,
> Malcolm
More information about the Python-list
mailing list