log
- class trap.log.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
Formatter- grey = '\x1b[38;20m'
- yellow = '\x1b[33;20m'
- red = '\x1b[31;20m'
- bold_red = '\x1b[31;1m'
- reset = '\x1b[0m'
- FORMATS = {10: '\x1b[38;20m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m', 20: '\x1b[38;20m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m', 30: '\x1b[33;20m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m', 40: '\x1b[31;20m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m', 50: '\x1b[31;1m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m'}
- format(record)[source]
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- trap.log.add_log_file_handler(log_dir: PathLike) Logger[source]
Add a file handler for all logging and a separete one for only errors and warnings. This makes the logger write both to the terminal and to a file in the specified log_dir location.
:param
os.PathLike: The location where the logs will be stored. Must be a directory.- Returns:
The updated logger that now also writes to log files
- Return type:
logging.Logger