Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81198 > unrolled thread

Re: Python Logging and printf()

Started byChris Angelico <rosuav@gmail.com>
First post2014-11-21 22:55 +1100
Last post2014-11-21 22:55 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python Logging and printf() Chris Angelico <rosuav@gmail.com> - 2014-11-21 22:55 +1100

#81198 — Re: Python Logging and printf()

FromChris Angelico <rosuav@gmail.com>
Date2014-11-21 22:55 +1100
SubjectRe: Python Logging and printf()
Message-ID<mailman.16098.1416570923.18130.python-list@python.org>
On Fri, Nov 21, 2014 at 9:48 PM, Ganesh Pal <ganesh1pal@gmail.com> wrote:
> Please provide your input on the below questions.
>
> (1). How do i guarantee that  all console messages will be logged into the
> logfile ?
> (2) I feel the  need to retain few print(), how do I ensure the print()
> messages are also logged into the log file.

If you're using Python 3, you can shadow print() with your own
function. The logging functions don't have the same signature, so
you'd need to write a wrapper (or else stick to a strict policy of
"one argument to print() and it must be a string"), but it's certainly
possible.

But part of the point of the logging module is that it's not the same
as console messages: you can reduce log spam by changing the logging
level. So no, you don't have a guarantee that all console messages
will be logged to the log file. If you want that, I would suggest a
process-level wrapper - something which invokes a subprocess with
redirected stdout and/or stderr - or, at very least, a startup routine
that does the redirection (which will have similar effect, except that
it can't catch startup failure messages from Python itself).

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web