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


Groups > comp.lang.python > #33173

Re: logging, can one get it to email messages over a certain level?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'root': 0.04; '"__main__":': 0.07; '__name__': 0.07; 'handlers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:messages': 0.09; 'that).': 0.09; 'steve': 0.13; 'do,': 0.15; 'gonna': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'terribly': 0.16; 'wrote:': 0.17; 'module': 0.19; 'sort': 0.21; 'bit': 0.21; 'import': 0.21; "i've": 0.23; 'header:User-Agent:1': 0.26; 'skip:m 30': 0.26; 'am,': 0.27; 'logging': 0.27; 'i.e.': 0.27; 'header:X-Complaints- To:1': 0.28; 'chris': 0.28; 'informative': 0.29; "i'm": 0.29; 'minimal': 0.30; 'error': 0.30; 'code': 0.31; 'gets': 0.32; 'url:python': 0.32; 'print': 0.32; 'certain': 0.33; '11,': 0.33; 'explains': 0.33; 'scroll': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'agree': 0.34; 'nov': 0.35; 'skip:l 30': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'thank': 0.36; 'possible': 0.37; 'ok,': 0.37; 'does': 0.37; 'level': 0.37; 'moment': 0.37; 'subject:: ': 0.38; 'green': 0.38; 'some': 0.38; 'url:docs': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'subject:, ': 0.61; 'here:': 0.62; 'subject:get': 0.81; 'subject:over': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: logging, can one get it to email messages over a certain level?
Date Mon, 12 Nov 2012 11:54:49 +0100
Organization None
References <ql45n9-lli.ln1@chris.zbmc.eu> <db43fde1-8edc-4839-a3b3-a742fffcfb22@me7g2000pbb.googlegroups.com> <k0t6n9-m6r.ln1@chris.zbmc.eu>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084b48f.dip.t-dialin.net
User-Agent KNode/4.7.3
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3578.1352717700.27098.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352717700 news.xs4all.nl 6934 [2001:888:2000:d::a6]:54513
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33173

Show key headers only | View raw


tinnews@isbd.co.uk wrote:

> Steve Howell <showell30@yahoo.com> wrote:
>> On Nov 11, 9:48 am, tinn...@isbd.co.uk wrote:
>> > I'm sure this must be possible but at the moment I can't see how to do
>> > it.
>> >
>> > I want to send an E-Mail when the logging module logs a message above
>> > a certain level (probably for ERROR and CRITICAL messages only).
>> >
>> > I.e. I want some sort of hook that will be called when these messages
>> > are logged (I can do the sendmail bit OK, I've got code that does
>> > that).
>> >
>> > --
>> > Chris Green
>> 
>> Scroll down to the Handlers section here:
>> 
>>    http://docs.python.org/2/howto/logging.html#logging-basic-tutorial
>> 
>> I'm not sure this explains perfectly what you're gonna need to do, but
>> I hope it gets you in the ballpark.
>> 
> Thank you, but yes I agree it's not terribly informative is it.

Here's a minimal example:

import logging
from logging.handlers import SMTPHandler

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)

    mail_handler = SMTPHandler(
        "smtp.example.com",
        "navigator@example.com",
        "captain.nemo@example.com",
        "fyi")
    mail_handler.setLevel(logging.CRITICAL)

    root = logging.getLogger()
    root.addHandler(mail_handler)

    # will print amessage
    root.warn("this is fishy") 

    # will print a message and send an email
    root.critical("giant squid sighted")

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


Thread

logging, can one get it to email messages over a certain level? tinnews@isbd.co.uk - 2012-11-11 17:42 +0000
  Re: logging, can one get it to email messages over a certain level? Steve Howell <showell30@yahoo.com> - 2012-11-11 09:56 -0800
    Re: logging, can one get it to email messages over a certain level? tinnews@isbd.co.uk - 2012-11-12 09:44 +0000
      Re: logging, can one get it to email messages over a certain level? Peter Otten <__peter__@web.de> - 2012-11-12 11:54 +0100
        Re: logging, can one get it to email messages over a certain level? tinnews@isbd.co.uk - 2012-11-12 11:36 +0000

csiph-web