Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
logging, can one get it to email messages over a certain level?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
tinn...@isbd.co.uk  
View profile  
 More options Nov 11 2012, 12:48 pm
Newsgroups: comp.lang.python
From: tinn...@isbd.co.uk
Date: Sun, 11 Nov 2012 17:42:50 +0000
Local: Sun, Nov 11 2012 12:42 pm
Subject: logging, can one get it to email messages over a certain level?
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Nov 11 2012, 12:56 pm
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Sun, 11 Nov 2012 09:56:46 -0800 (PST)
Local: Sun, Nov 11 2012 12:56 pm
Subject: Re: logging, can one get it to email messages over a certain level?
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tinn...@isbd.co.uk  
View profile  
 More options Nov 12 2012, 4:47 am
Newsgroups: comp.lang.python
From: tinn...@isbd.co.uk
Date: Mon, 12 Nov 2012 09:44:20 +0000
Local: Mon, Nov 12 2012 4:44 am
Subject: Re: logging, can one get it to email messages over a certain level?

Thank you, but yes I agree it's not terribly informative is it.

However I think I understand what I need to do.  I currently have a
function to set up my logging:-

    def initLog(name):
        log = logging.getLogger(name)
        log.setLevel(logging.DEBUG)
        f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 1000000, 4)
        f.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        f.setFormatter(formatter)
        log.addHandler(f)
        return log

As I understand it I just add another line like the 'f =' line but
using the SMTPHandler and then set an appropriate level for that
handler (and formatting).

--
Chris Green


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Otten  
View profile  
 More options Nov 12 2012, 5:55 am
Newsgroups: comp.lang.python
From: Peter Otten <__pete...@web.de>
Date: Mon, 12 Nov 2012 11:54:49 +0100
Local: Mon, Nov 12 2012 5:54 am
Subject: Re: logging, can one get it to email messages over a certain level?

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",
        "naviga...@example.com",
        "captain.n...@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")


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tinn...@isbd.co.uk  
View profile  
 More options Nov 12 2012, 6:47 am
Newsgroups: comp.lang.python
From: tinn...@isbd.co.uk
Date: Mon, 12 Nov 2012 11:36:47 +0000
Local: Mon, Nov 12 2012 6:36 am
Subject: Re: logging, can one get it to email messages over a certain level?

Thank you.

--
Chris Green


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »