Advanced Python Tips




Pay Notebook Creator: Roy Hyunjin Han0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

20170731-1515 - 20170731-1530: 15 minutes

Here we briefly want to check that we can set logging at the package level and have the same logging configuration apply to its subpackages.

  1. Configure logging for "whee" to include DEBUG messages
  2. Check that we can see the DEBUG message sent to "whee"
  3. Check that we can see the DEBUG message sent to "whee.plus"
In [1]:
import logging
logging.getLogger('whee').setLevel(logging.DEBUG)
logging.basicConfig()
In [2]:
log = logging.getLogger('whee')
log.debug('made you look')
DEBUG:whee:made you look
In [3]:
log = logging.getLogger('whee.plus')
log.debug('made you look again')
DEBUG:whee.plus:made you look again

In conclusion, we can safely configure logging at the package level and use logging.getLogger(__name__) in each subpackage.