pip install logbook
python
import logbook
python
my_logger = logbook.Logger('My Logger')
python
my_logger.debug('This is a debug message.')
python
logbook.StreamHandler(sys.stdout, format_string='[{record.level_name}] {record.time:%Y-%m-%d %H:%M:%S} - {record.message}').push_application()
python
logbook.FileHandler('my_logbook.log').push_application()
python
mail_handler = logbook.MailHandler(from_addr='sender@example.com', to_addr='receiver@example.com', \
subject='Error Log', level=logbook.ERROR, mailhost='smtp.example.com', \
credentials=('username', 'password'), secure=True, bubble=True)
mail_handler.push_application()