-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.py
28 lines (24 loc) · 977 Bytes
/
Logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
import logging.handlers
import yagmail
import datetime
# Create logger
logging.basicConfig(level = logging.DEBUG)
main_logger = logging.getLogger(__name__)
# Create handlers
file_handler = logging.FileHandler('./app.log', 'w') # Setting to 'w' erases log on startup.
file_format = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(file_format)
file_handler.setLevel(logging.DEBUG)
main_logger.addHandler(file_handler)
def send_log_email():
"""
Sends an email from a temporary gmail account to the developer containing the log file generated during the user session.
"""
yagmail.register('[email protected]', '972305Bot')
email_sender = yagmail.SMTP("[email protected]").send(
to="[email protected]",
subject=f"{datetime.datetime.now()} - Program log",
contents="User has closed the program, log attached",
attachments="app.log",
)