[issue22195] Make it easy to replace print() calls with logging calls

2019-04-26 Thread Mark Lawrence
Change by Mark Lawrence : -- nosy: -BreamoreBoy ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-17 Thread Martin Matusiak
Martin Matusiak added the comment: Would it make sense for the logging module to supply something like the LoggerWriter class you wrote? With a section in the documentation that says something like have you been logging using print() this whole time? No problem, just do sys.stdout =

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-17 Thread Vinay Sajip
Vinay Sajip added the comment: Would it make sense for the logging module to supply something like the LoggerWriter class you wrote? Perhaps I'm not making myself clear :-( I've posted the LoggerWriter class (not the initial version, but the later, slightly more functional one) to see if

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-17 Thread Antoine Pitrou
Antoine Pitrou added the comment: However, from a smoke test, sys.stdout = LoggerWriter() doesn't seem to work as expected I wasn't thinking about replacing sys.stdout (which I think is in general a bad pattern, except for daemonized processes), rather being able to 1) either replace the

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-17 Thread Vinay Sajip
Vinay Sajip added the comment: Loggers don't deal with output - handlers do - so I would prefer not to add an output-related method to a logger: people confuse the two enough as it is. Note that stream = LoggerWriter('foo') gives an equivalent result to stream =

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-16 Thread Martin Matusiak
Martin Matusiak added the comment: Hm, on this model you still have to go and update all your print() statements with the file= argument. That's less invasive than replacing them with logger.info(), but still not very elegant. You're also repeating the stream on every occurrence, so easy to

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-16 Thread Vinay Sajip
Vinay Sajip added the comment: but still not very elegant. You're also repeating the stream on every occurrence, so easy to leave it out by mistake. It might need more work to make a LoggerWriter work with sys.stdout [i.e. allowing sys.stdout = LoggerWriter()], which seems to be the only

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-15 Thread Vinay Sajip
Vinay Sajip added the comment: Here's a tentative suggestion. Does it meet your needs? import logging import sys class LoggerWriter(object): def __init__(self, logger='', level=logging.DEBUG): if isinstance(logger, str): logger = logging.getLogger(logger)

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-15 Thread Barry A. Warsaw
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22195 ___ ___ Python-bugs-list mailing

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-14 Thread Antoine Pitrou
New submission from Antoine Pitrou: Often an application (or e.g. a library's test suite), in its early development, will start making print() calls, and later will want to switch to the logging module. However the logging module doesn't offer any facility for this: you can't print() to a

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-14 Thread Mark Lawrence
Changes by Mark Lawrence breamore...@yahoo.co.uk: -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22195 ___ ___

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-14 Thread Saimadhav Heblikar
Changes by Saimadhav Heblikar saimadhavhebli...@gmail.com: -- nosy: +sahutd ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22195 ___ ___

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-14 Thread Vinay Sajip
Vinay Sajip added the comment: This is easy enough to do, I posted about it in 2009 here: http://plumberjack.blogspot.co.uk/2009/09/how-to-treat-logger-like-output-stream.html Basically, something like class LoggerWriter(object): def __init__(self, logger, level): self.logger =

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-14 Thread Antoine Pitrou
Antoine Pitrou added the comment: This is easy enough to do, I posted about it in 2009 here I know it's easy. It's still annoying to have to write such boilerplate by hand (especially when everyone ends up rewriting the exact same one). -- ___

[issue22195] Make it easy to replace print() calls with logging calls

2014-08-14 Thread Raymond Hettinger
Raymond Hettinger added the comment: This is a recurring problem. I concur with Antoine that there needs to be logging functions that are harmonized with print(). -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org