[Python-ideas] add a LogReader to the logging module

terji78 at gmail.com terji78 at gmail.com
Wed May 10 11:40:01 EDT 2017

I get a message back that I'm not subscribed to the mailing list, but see 
my message in google groups. My sincerest apologies in advance, if this 
appears several times for you. Anyways:

The logging module has an easy-to-setup logger:

    import logging
    logger = logging.getLogger(__name__)
and you just log away. Easy.

However, it's quite a bit more difficult to set up log readers, requiring 
IMO an unreasonably number of lines of code:

    import logging

    logger = logging.getLogger('mypackage')
    handler = logging.StreamHandler()
    formatter = logging.Formatter('%(

I propose adding a function that sets up a log reader with sensible 
defaults, but allowing customization. So, I propose a 
``logging.getLogReader`` in the logging module to mirror 
``logging.getLogger``. So, to use this, in your main.py, you'd typically 
just do:

    import logging

    log_reader = logging.getLogReader('mypackage.models')

and you'd get all log output from mypackage.models with sensible defaults 
set. Much easier. 

You could also set up it up in more detail, e.g.:

    log_reader = logging.getLogReader('mypackage.models',
                                      format='%(levelname)s | %(filename)s| 
line %(lineno)s | %(message)s'

For a specific proposal, see:


Because it's just a logger, log_reader can be further customized as 

In summary, I think  that today it's unneccesarily complex to set up a log 
reader and the proposed function serves a general enough need, that it - or 
something similar - should be in the logging module. Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170510/34a1b480/attachment.html>

More information about the Python-ideas mailing list