Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

logging errors into emails

import logging
from logging.handlers import SMTPHandler

mail_handler = SMTPHandler(
    mailhost='127.0.0.1',
    fromaddr='server-error@example.com',
    toaddrs=['admin@example.com'],
    subject='Application Error'
)
mail_handler.setLevel(logging.ERROR)
mail_handler.setFormatter(logging.Formatter(
    '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'
))

if not app.debug:
    app.logger.addHandler(mail_handler)
Comment

PREVIOUS NEXT
Code Example
Python :: walk nested dict python 
Python :: asterisk triangle print 
Python :: how to convert matlab code into python 
Python :: Find Factors of a Number using While Loop with validation 
Python :: Command to import Required, All, Length, and Range from voluptuous 
Python :: Simple Python Permutation Without Passing any argument 
Python :: Accessing element using negative indexing 
Python :: python finding mead 
Python :: cubic interpolation python 
Python :: merge sort dictionary python 
Python :: sys exit out of loop 
Python :: python set vs tuple performance 
Python :: velocity field gradient 
Python :: dict keys in tcl 
Python :: __len__ in python 
Python :: docker python run subprocess python run docker interactively subprocess 
Python :: Python NumPy ndarray flatten Function Example 02 
Python :: python text file contains 
Python :: Python NumPy asfortranarray Function List to an array 
Python :: Python NumPy array_split Function Example 02 
Python :: emit data to specific client socketio python 
Python :: Python how to use __sub__ 
Python :: hide ticks without hiding grid 
Python :: NumPy bitwise_xor Code When inputs are Boolean 
Python :: python code to scan paper table to excel 
Python :: how to calculate iqr in pandas 
Python :: create loop python 
Python :: lda from scratch implementation on iris python 
Python :: Examples of correct code for this rule with global declaration: 
Python :: Permission error 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =