Logging Setup

Set of functions that culminate in logging_setup, which deals with setup of everything related to logging throughout the rest of the bot

class logger_util.SSLSMTPHandler(mailhost, fromaddr, toaddrs, subject, **kwargs)

Bases: logging.handlers.SMTPHandler

Subclass of the builtin SMTP logging handler that uses SSL to send email messages Used in this bot to send emails when a critical error has occured

emit(record: logging.LogRecord) → None

Emit a record.

Format the record and send it to the specified addressees.

class logger_util.SelfCleaningRotatingTimedFileHandler(filename, when='midnight', interval=1)

Bases: logging.handlers.TimedRotatingFileHandler

Subclass of the builtin TimedRotatingFileHandler logging handler that changes to a new file at midnight. When it does this it also goes and cleans up the directory that contains the log files

doRollover() → None

do a rollover; in this case, a date/time stamp is appended to the filename when the rollover happens. However, you want the file to be named for the start of the interval, not the current time. If there is a backup count, then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix.

logger_util.log_file_name(directory: str) → str

Generates the name for a log file based off the current time

logger_util.logging_cleanup(capacity: int = 5) → None

If there are more than capacity log files in the directory, delete the oldest file until there are less than capacity

logger_util.logging_setup(p_logger: logging.Logger) → None

Sets up a file handler in the directory specified by OS variables and sets up a stream handler to log everything to stdout as well @param p_logger: The logger which we are adding these handlers to

logger_util.optional_make_dir(directory: str) → None

Checks if dir exists, if it doesn’t we go make that directory