OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

python logging: email entire log file as attachment when level >= ERROR

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

Guest
My logging system has a few handlers, log file (INFO), an email handler (>ERROR), and a stream handler for optional debugging. When an error/exception/critical message occurs, I want the email handler to attach the log file from the file handler to the error email.

Code:
import logging

def initialize_logging():
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    file_handler = createFileHandler()
    file_handler.setLevel(logging.INFO)
    logger.addHandler(file_handler)

    email_handler = createEmailHandler(file_handler.baseFilename)
    email_handler.setLevel(logging.ERROR)
    logger.addHandler(email_handler)

I found this example, but it's basically writing the handler from scratch. https://gist.github.com/LavinJ/238ccb229ac594a50b0a

I'd love if there was a simpler means of modifying the existing SMTPHandler
<p>My logging system has a few handlers, log file (INFO), an email handler (>ERROR), and a stream handler for optional debugging. When an error/exception/critical message occurs, I want the email handler to attach the log file from the file handler to the error email.</p>

<pre><code>import logging

def initialize_logging():
logger = logging.getLogger()
logger.setLevel(logging.INFO)

file_handler = createFileHandler()
file_handler.setLevel(logging.INFO)
logger.addHandler(file_handler)

email_handler = createEmailHandler(file_handler.baseFilename)
email_handler.setLevel(logging.ERROR)
logger.addHandler(email_handler)
</code></pre>

<p>I found this example, but it's basically writing the handler from scratch. <a href="https://gist.github.com/LavinJ/238ccb229ac594a50b0a" rel="nofollow">https://gist.github.com/LavinJ/238ccb229ac594a50b0a</a> </p>

<p>I'd love if there was a simpler means of modifying the existing SMTPHandler</p>
Continue reading...
 

Latest posts

Top