add a LogReader to the logging module

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') logger.setLevel(logging.DEBUG) handler = logging.StreamHandler() formatter = logging.Formatter('%( levelname)s:%(name)s:%(message)s') handler.setFormatter(formatter) logger.addHandler(handler) 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', level='debug', format='%(levelname)s | %(filename)s| line %(lineno)s | %(message)s' ) For a specific proposal, see: https://gist.github.com/topper-123/85e27ffe261850eed150eac53d61b82d Because it's just a logger, log_reader can be further customized as necessary. 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?

Hi! Isn't it just basicConfig? import logging logging.basicConfig( filename='test.log', format='[%(asctime)s] %(name)s %(levelname)s: %(message)s', level=logging.DEBUG, ) log = logging.getLogger("TEST") On Wed, May 10, 2017 at 08:40:01AM -0700, terji78@gmail.com wrote:
Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

Hi! Isn't it just basicConfig?
BasicConfig does not allow different settings for different log readers, as I can see. E.g. import logging logging.basicConfig( level=logging.DEBUG, ) log1 = logging.getLogger("TEST1") logging.basicConfig( level=logging.INFO, ) log2 = logging.getLogger("TEST2") Here log2 will write out logs at the same level as log1, so basicConfic is IMO too basic for a lot of use cases and so you'll have to go through the other more verbose setup. So, this getLogReader function would be more general than basicConfig, but also much more useful. (But please educate me, if I've misunderstood basicConfig)

The basicConfig sets the root (or "") logger, any messages from other loggers will end in the root logger if the propagation setting is enabled. There is the misconception that with the logging module you could have completely different loggers. In reality there is only 'one' logger, but with the hierarchy of names and some logic you could use as if there is more than one logger. Also in your propose the name of getLoggerReader is misleading as this implies that there is something to read, there is not, a log event is something to process, write if you wish (this is the purpose of handlers). Regards!

Hi! Isn't it just basicConfig? import logging logging.basicConfig( filename='test.log', format='[%(asctime)s] %(name)s %(levelname)s: %(message)s', level=logging.DEBUG, ) log = logging.getLogger("TEST") On Wed, May 10, 2017 at 08:40:01AM -0700, terji78@gmail.com wrote:
Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

Hi! Isn't it just basicConfig?
BasicConfig does not allow different settings for different log readers, as I can see. E.g. import logging logging.basicConfig( level=logging.DEBUG, ) log1 = logging.getLogger("TEST1") logging.basicConfig( level=logging.INFO, ) log2 = logging.getLogger("TEST2") Here log2 will write out logs at the same level as log1, so basicConfic is IMO too basic for a lot of use cases and so you'll have to go through the other more verbose setup. So, this getLogReader function would be more general than basicConfig, but also much more useful. (But please educate me, if I've misunderstood basicConfig)

The basicConfig sets the root (or "") logger, any messages from other loggers will end in the root logger if the propagation setting is enabled. There is the misconception that with the logging module you could have completely different loggers. In reality there is only 'one' logger, but with the hierarchy of names and some logic you could use as if there is more than one logger. Also in your propose the name of getLoggerReader is misleading as this implies that there is something to read, there is not, a log event is something to process, write if you wish (this is the purpose of handlers). Regards!
participants (3)
-
Agustín Herranz Cecilia
-
Oleg Broytman
-
terji78@gmail.com