Python logging message not getting output as expected in simplest scenario
Question: I am not getting any output from `logging.debug` in the simplest possible
situation. (I do get output from `logger.warn`.)

    
    
    import logging
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    logger.warn('Logger is warning')
    logger.debug('Logger is debugging')
    print(logger.getEffectiveLevel(),
          logger.isEnabledFor(logging.DEBUG),
          file=sys.stderr)
    

The last line prints the logger's logging level, which shows as
`logging.DEBUG`, and whether the logger is enabled for that level, which is
true. yet output appears for `log.warn` but not for `log.debug`. What am I
missing?

[Python 3.5, OS X 10.11]


Answer: The reason is that you haven't specified a handler. On Python 3.5, an internal
["handler of last
resort"](https://docs.python.org/3.2/library/logging.html#logging.lastResort)
is used when no handler is specified by you, but that internal handler has a
level of `WARNING` and so won't show messages of lower severity. You need to
specify a handler and add it like this example:

    
    
    logger.addHandler(logging.StreamHandler())
    

either just before or just after the `setLevel` statement in your snippet.

