Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81451
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ganesh1pal@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'root': 0.05; 'skip:l 60': 0.07; 'sys': 0.07; 'skip:/ 10': 0.09; 'python': 0.11; 'suggest': 0.14; '"error': 0.16; 'abort': 0.16; 'logger': 0.16; 'stdout': 0.16; 'subject:PYTHON': 0.16; 'import': 0.22; 'team,': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'error': 0.23; 'skip:% 10': 0.24; 'skip:l 30': 0.24; '>': 0.26; 'logging': 0.26; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'file': 0.32; 'screen': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'info': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'displays': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'ensure': 0.60; 'logs': 0.60; 'levels': 0.65; 'url:info': 0.73; 'subject:skip:S 10': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=x8wm1/RYjL3FzfsX4MjXxCElAihmroso0eAKitfcQYA=; b=pf58ijdrW+UsGSxPWQJUQdhErZdQURw/lQw3g5+IQN/s0ryQLG4Ek13q7nxkxzTo8N i7xznUtIVfaXaTiBr3k3HA6ICOEI6sqljiOAtdN/hpYSQ7a8SSVfYXsPjSXeUg0jkd4J Qi1h6di2z/Pk8CsF2soPiEL/lnnpC/0v2mmEf/D3r8kyyaY2AUtNoCOVmRVWUoVomeRu /NxWPjSRDIp6T66j1EruLyZd6SqqnPZ5CDEqGJQELJjpMH/paLvzHMoGqn6QoXxOdRzp MnwX3A7P16Vk2Fgsxjh58HEexkAJJpOEAatmAjYuzdfP1qpOsptz38g1wztPrR4HKBDs z4Kg== |
| MIME-Version | 1.0 |
| X-Received | by 10.152.120.133 with SMTP id lc5mr20095113lab.62.1416829092681; Mon, 24 Nov 2014 03:38:12 -0800 (PST) |
| Date | Mon, 24 Nov 2014 17:08:12 +0530 |
| Subject | PYTHON LOGGING with StreamHandler and FileHandler |
| From | Ganesh Pal <ganesh1pal@gmail.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=089e01176919c6dd3f0508993a42 |
| 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.16245.1416829096.18130.python-list@python.org> (permalink) |
| Lines | 92 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1416829096 news.xs4all.nl 2919 [2001:888:2000:d::a6]:49775 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81451 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi Team,
The below program logs all the messages to the log file and displays the
same on the console .
Please suggest how do I ensure that error and warning log levels go ONLY to
stdout and/or stder
Code :
import logging
import sys
# StreamHandler
root = logging.getLogger()
root.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
# FileHandler
logger = logging.getLogger('myapp')
ch = logging.FileHandler('/var/tmp/myapp1.log')
logger.setLevel(logging.DEBUG)
logger.error('We have a problem')
logger.info('While this is just chatty')
print "error abort" ## should be displayed on screen with using
loggin.<something>
output :
# python modified_logger.py
2014-11-24 11:18:12,355 - myapp - ERROR - We have a problem
2014-11-24 11:18:12,356 - myapp - INFO - While this is just chatty
error abort
# echo > /var/tmp/myapp1.log
# python modified_logger.py
2014-11-24 11:18:45,872 - myapp - ERROR - We have a problem
2014-11-24 11:18:45,872 - myapp - INFO - While this is just chatty
error abort
Regards,
Ganesh
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
PYTHON LOGGING with StreamHandler and FileHandler Ganesh Pal <ganesh1pal@gmail.com> - 2014-11-24 17:08 +0530
csiph-web