Logging at Gevent application
Question: I'm trying to use standard Python logging module alongside with gevent. I have
monkey patched threading and I expect logging to work with my app:

    
    
    import gevent.monkey
    gevent.monkey.patch_all()
    
    import logging
    
    logger = logging.getLogger()
    fh = logging.FileHandler('E:\\spam.log')
    fh.setLevel(logging.DEBUG)
    logger.addHandler(fh)
    
    def foo():
        logger.debug('Running in foo')
        gevent.sleep(0)
        logger.debug('Explicit context switch to foo again')
    
    def bar():
        logger.debug('Explicit context to bar')
        gevent.sleep(0)
        logger.debug('Implicit context switch back to bar')
    
    
    gevent.joinall([
        gevent.spawn(foo),
        gevent.spawn(bar),
    ])
    

Unfortunately E:\spam.log is empty and I can see no output to the console. It
seems that either I haven't configured logging properly or gevent does not
support it at all (which I don't believe, because gevent documentation says
that it [does](http://learn-gevent-
socketio.readthedocs.org/en/latest/gevent.html#examples)). So, how can I log
at gevent app?


Answer: You haven't configured it correctly. You need to set the `DEBUG` level on the
logger rather than the handler, otherwise the logger's default level
(`WARNING`) causes your debug messages to be dropped. Try doing a

    
    
    logger.setLevel(logging.DEBUG)
    

and it should work.

