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


Groups > comp.lang.python > #81198

Re: Python Logging and printf()

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'startup': 0.05; 'subject:Python': 0.06; '21,': 0.07; 'redirected': 0.07; 'strict': 0.07; 'subject:()': 0.09; 'wrapper': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'suggest': 0.14; 'effect,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'invokes': 0.16; 'itself).': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'subject:Logging': 0.16; 'wrote:': 0.18; 'module': 0.19; 'input': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'stick': 0.24; 'file.': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'logging': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'routine': 0.31; 'fri,': 0.33; 'level.': 0.33; "can't": 0.35; 'except': 0.35; 'possible.': 0.35; 'something': 0.35; '(2)': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'similar': 0.36; 'changing': 0.37; 'nov': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'how': 0.40; 'ensure': 0.60; 'catch': 0.60; 'logged': 0.60; "you're": 0.61; 'guarantee': 0.63; 'provide': 0.64; '"one': 0.84; 'shadow': 0.84; 'messages:': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=07OAMP8683KQm+/gevhpWSOb+iqejuaalwPjp5FCkj0=; b=yg1Xi7MSk2g3cyprUxalQ7qX5xLV+W0dDNO09Uujw/IpI10e3gmi3N31vHGLAdkbIK WlIdYpD46MpzsOt+bTkmgKDRXusiKd5R2nXShj0JaG/TXVUERtnL4VXxAby2MESo5iMI oTtGB+D10vX9skflnctRPPgZRbQk3sbzkNTD4Vok51wZV0eSYq1+fuzOZlJN/MjCHnz4 l4LYDAgvpRVfBCEzrib/D0YaiTIeQ+0OFEm5uYrfgd7DQzrOMyTTWGuyxUuYz2wT3+dt wwKKtc2hSnXFYHJrGRQtWTuqxpz3cTZAOffdmiobl/7Yqg5Z9pTgcTsfa7c3K52rKzSO op0A==
MIME-Version 1.0
X-Received by 10.42.64.143 with SMTP id g15mr5195044ici.59.1416570915599; Fri, 21 Nov 2014 03:55:15 -0800 (PST)
In-Reply-To <CACT3xuV7c0jQ_yj_+BU28t3B_tcr9mTAtNefiiBcAe1dPQmnbQ@mail.gmail.com>
References <CACT3xuV7c0jQ_yj_+BU28t3B_tcr9mTAtNefiiBcAe1dPQmnbQ@mail.gmail.com>
Date Fri, 21 Nov 2014 22:55:15 +1100
Subject Re: Python Logging and printf()
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16098.1416570923.18130.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416570923 news.xs4all.nl 2859 [2001:888:2000:d::a6]:48754
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81198

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web