[issue16391] add "terminator" ctor argument to logging.StreamHandlers derived handlers

Vinay Sajip report at bugs.python.org
Mon Nov 12 17:24:06 CET 2012


Vinay Sajip added the comment:

I don't understand what you mean. For example, defining

def my_handler(*args, **kwargs):
    terminator = kwargs.pop('terminator', '!\n')
    h = logging.StreamHandler(*args, **kwargs)
    h.terminator = terminator
    return h

you can use with a definition of the handler such as

    'console': {
        '()': 'ext://__main__.my_handler',
        'stream': 'ext://sys.stdout',
        'terminator': '!\n',
    }

or similar. And you can also do something this with your own subclass, instead of a function as per my example.

ISTM that using subclasses is the right way to approach this problem; otherwise why would one *ever* use subclasses? I use them when the base class doesn't do exactly what I want, but offers extension points to change its behaviour via subclassing.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16391>
_______________________________________


More information about the Python-bugs-list mailing list