Log_File¶
The Log_File enables you to set up logging to a file that is saved for future access to persist the logs. Also enables the ability to output the logs to the console (STDOUT) if you desire.
Usage¶
You can use this module in a few ways
Import the whole py4pa package:
import py4pa log = py4pa.Log_File( directory = '/users/me/documents' ) log.info('Info message')
Import the module directly:
from py4pa import Log_File log = Log_File( directory = '/users/me/documents' ) log.info('Info message')
Documentation¶
- class py4pa.Log_File(directory, fName=None, log_level='INFO', log_fmt='%(asctime)s: %(levelname)s %(message)s', print_to_console=False)¶
Bases:
objectPython class to enable logging of key events to a file of your choosing, as well as the console if you wish
- Parameters:
directory (str) – The file location where you want the log file saved, excluding the file name
fName (str (optional)) – The filename, including extension that you want to use as your output. If this isn’t specified, the file will be called ‘progress_log - YYYY-MM-DD HH:MM:SS.txt’, where the date & time stamp will be the time when the log is first initiated.
log_level (str (optional)) – Defaults to ‘INFO’. Valid options are NOTSET, DEBUG, INFO, WARN, ERROR, CRITICAL
log_fmt (str (optional)) – See https://docs.python.org/3/library/logging.html#logging.LogRecord for definitions of attributes. Defaults to ‘%(asctime)s: %(levelname)s %(message)s’ e.g. ‘2024-03-14 10:56:54,329: INFO test info message’
print_to_console (bool (optional)) – Defaults to True. If set to true, will print messages to both the log file, and the console. If False, will only output to the log file
- critical(msg)¶
- debug(msg)¶
- error(msg)¶
- info(msg)¶
- warning(msg)¶