Package: shouterlog
Shouter Usage ExamplesThe Shouter class is designed for managing and displaying formatted log messages, utilizing Python's logging module.importsyssys.path.append('../')frompython_modules.shouterlogimportShouter# optionalimportloggingUsage examplesThe examples contain:initialize Shouter classbasic usage like loggingusing different output typescustom logger configurationbackwards compatibility with existing loggersbuilt-in records from Shouter usagedebugging capabilities of Shouter1. Initialize Shouter Classshouter=Shouter(# optional/ requiredsupported_classes=(),# optionally## Formatting settingsdotline_length=50,auto_output_type_selection=True,# For saving recordstears_persist_path='../env_spec/log_records.json',datetime_format="%Y-%m-%d%H:%M:%S",# For saving envpersist_env=False,env_persist_path='../env_spec/environment.dill',## Logger settingslogger=None,logger_name='Shouter',loggerLvl=logging.DEBUG,logger_format='(%(asctime)s) :%(name)s: [%(levelname)s] :%(message)s')2. Basic usage like loggingshouter.debug(# optionaldotline_length=30)shouter.debug("This is a debug message!")shouter.info("This is an info message!")shouter.warning("This is a warning message!")shouter.error("This is an error message!")shouter.fatal("This is a fatal message!")shouter.critical("This is a critical message!")(2024-01-14 22:39:52,280) : Shouter : [DEBUG] : ==============================
(2024-01-14 22:39:52,292) : Shouter : [DEBUG] : This is a debug message!
(2024-01-14 22:39:52,296) : Shouter : [INFO] : This is an info message!
(2024-01-14 22:39:52,304) : Shouter : [WARNING] : This is a warning message!
(2024-01-14 22:39:52,307) : Shouter : [ERROR] : This is an error message!
(2024-01-14 22:39:52,310) : Shouter : [CRITICAL] : This is a fatal message!
(2024-01-14 22:39:52,313) : Shouter : [CRITICAL] : This is a critical message!3. Using different output types# Different types of outputsshouter.info(output_type="dline")shouter.info(output_type="HEAD1",mess="Header Message")(2024-01-14 22:39:52,399) : Shouter : [INFO] : ==================================================
(2024-01-14 22:39:52,402) : Shouter : [INFO] : 
==================================================
-----------------Header Message----------------- 
==================================================4. Custom logger configurationimportlogging# Custom loggercustom_logger=logging.getLogger("CustomLogger")custom_logger.setLevel(logging.INFO)# Shouter with custom loggershouter_with_custom_logger=Shouter(supported_classes=(),logger=custom_logger)shouter_with_custom_logger.info(mess="Message with custom logger")(2024-01-14 22:39:52,429) : CustomLogger : [INFO] : Message with custom logger5. Backwards compatibility with existing loggersimportloggingimportattr#>=22.2.0@attr.sclassExampleClass:# Logger settingslogger=attr.ib(default=None)logger_name=attr.ib(default='Example Class')loggerLvl=attr.ib(default=logging.DEBUG)logger_format=attr.ib(default='(%(asctime)s) :%(name)s: [%(levelname)s] :%(message)s')def__attrs_post_init__(self):self.initialize_logger()definitialize_logger(self):"""Initialize a logger for the class instance based onthe specified logging level and logger name."""ifself.loggerisNone:logging.basicConfig(level=self.loggerLvl,format=self.logger_format)logger=logging.getLogger(self.logger_name)logger.setLevel(self.loggerLvl)self.logger=loggerdefprint_debug(self):self.logger.debug("This is a debug message!")defprint_info(self):self.logger.info("This is a info message!")defprint_warning(self):self.logger.warning("This is a warning message!")defprint_error(self):self.logger.error("This is a error message!")defprint_critical(self):self.logger.critical("This is a critical message!")defperform_action_chain_1(self):self.logger.debug("Action 1")self.print_debug()self.logger.debug("Action 2")self.print_error()defperform_action_chain_2(self):a=1b='b'c=['list']d={'key':'value'}e=Shouter()self.logger.error("Saving env")ec=ExampleClass()ec.print_debug()ec.print_info()ec.print_warning()ec.print_error()ec.print_critical()(2024-01-14 22:39:52,478) : Example Class : [DEBUG] : This is a debug message!
(2024-01-14 22:39:52,482) : Example Class : [INFO] : This is a info message!
(2024-01-14 22:39:52,484) : Example Class : [WARNING] : This is a warning message!
(2024-01-14 22:39:52,486) : Example Class : [ERROR] : This is a error message!
(2024-01-14 22:39:52,488) : Example Class : [CRITICAL] : This is a critical message!shouter_for_example_class=Shouter(supported_classes=(ExampleClass),tears_persist_path='../env_spec/log_records.json')ec=ExampleClass(logger=shouter_for_example_class)ec.print_debug()ec.print_info()ec.print_warning()ec.print_error()ec.print_critical()ec.perform_action_chain_1()(2024-01-14 22:39:52,506) : Shouter : [DEBUG] : This is a debug message!
(2024-01-14 22:39:52,508) : Shouter : [INFO] : This is a info message!
(2024-01-14 22:39:52,510) : Shouter : [WARNING] : This is a warning message!
(2024-01-14 22:39:52,512) : Shouter : [ERROR] : This is a error message!
(2024-01-14 22:39:52,518) : Shouter : [CRITICAL] : This is a critical message!
(2024-01-14 22:39:52,521) : Shouter : [DEBUG] : Action 1
(2024-01-14 22:39:52,522) : Shouter : [DEBUG] : + This is a debug message!
(2024-01-14 22:39:52,524) : Shouter : [DEBUG] : Action 2
(2024-01-14 22:39:52,526) : Shouter : [ERROR] : + This is a error message!6. Built-in records from Shouter usageshouter_for_example_class=Shouter(supported_classes=(ExampleClass),tears_persist_path='../env_spec/log_records.json')ec=ExampleClass(logger=shouter_for_example_class)ec.print_debug()ec.perform_action_chain_1()(2024-01-14 22:39:52,551) : Shouter : [DEBUG] : This is a debug message!
(2024-01-14 22:39:52,554) : Shouter : [DEBUG] : Action 1
(2024-01-14 22:39:52,556) : Shouter : [DEBUG] : + This is a debug message!
(2024-01-14 22:39:52,558) : Shouter : [DEBUG] : Action 2
(2024-01-14 22:39:52,560) : Shouter : [ERROR] : + This is a error message!ec.logger.return_logged_tears()[{'datetime': '2024-01-14 22:39:52',
  'level': 'debug',
  'function': 'ExampleClass.print_debug',
  'mess': 'This is a debug message!',
  'line': 33,
  'lines': [33],
  'traceback': ['ExampleClass.print_debug']},
 {'datetime': '2024-01-14 22:39:52',
  'level': 'debug',
  'function': 'ExampleClass.perform_action_chain_1',
  'mess': 'Action 1',
  'line': 53,
  'lines': [53],
  'traceback': ['ExampleClass.perform_action_chain_1']},
 {'datetime': '2024-01-14 22:39:52',
  'level': 'debug',
  'function': 'ExampleClass.perform_action_chain_1',
  'mess': 'This is a debug message!',
  'line': 54,
  'lines': [33, 54],
  'traceback': ['ExampleClass.print_debug',
   'ExampleClass.perform_action_chain_1']},
 {'datetime': '2024-01-14 22:39:52',
  'level': 'debug',
  'function': 'ExampleClass.perform_action_chain_1',
  'mess': 'Action 2',
  'line': 56,
  'lines': [56],
  'traceback': ['ExampleClass.perform_action_chain_1']},
 {'datetime': '2024-01-14 22:39:52',
  'level': 'error',
  'function': 'ExampleClass.perform_action_chain_1',
  'mess': 'This is a error message!',
  'line': 57,
  'lines': [45, 57],
  'traceback': ['ExampleClass.print_error',
   'ExampleClass.perform_action_chain_1']}]importpandasaspdpd.DataFrame(ec.logger.return_logged_tears())<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>datetimelevelfunctionmesslinelinestraceback02024-01-14 22:39:52debugExampleClass.print_debugThis is a debug message!33[33][ExampleClass.print_debug]12024-01-14 22:39:52debugExampleClass.perform_action_chain_1Action 153[53][ExampleClass.perform_action_chain_1]22024-01-14 22:39:52debugExampleClass.perform_action_chain_1This is a debug message!54[33, 54][ExampleClass.print_debug, ExampleClass.perfor...32024-01-14 22:39:52debugExampleClass.perform_action_chain_1Action 256[56][ExampleClass.perform_action_chain_1]42024-01-14 22:39:52errorExampleClass.perform_action_chain_1This is a error message!57[45, 57][ExampleClass.print_error, ExampleClass.perfor...7. Debugging capabilities of Shoutershouter_for_example_class=Shouter(supported_classes=(ExampleClass),tears_persist_path='../env_spec/log_records.json',persist_env=True,env_persist_path='../env_spec/environment.dill')ec=ExampleClass(logger=shouter_for_example_class)ec.print_debug()ec.perform_action_chain_2()(2024-01-14 22:39:53,277) : Shouter : [DEBUG] : This is a debug message!
(2024-01-14 22:39:53,280) : Shouter : [ERROR] : Saving env
(2024-01-14 22:39:53,348) : Shouter : [WARNING] : Object 'self' could not have been serialized, when saving last words!ec.logger.return_last_words(# optionalenv_persist_path='../env_spec/environment.dill'){'a': 1,
 'b': 'b',
 'c': ['list'],
 'd': {'key': 'value'},
 'e': Shouter(supported_classes=(), dotline_length=50, auto_output_type_selection=True, tears_persist_path='log_records.json', env_persist_path='environment.dill', datetime_format='%Y-%m-%d %H:%M:%S', log_records=[], persist_env=False, logger=<Logger Shouter (DEBUG)>, logger_name='Shouter', loggerLvl=10, logger_format='(%(asctime)s) : %(name)s : [%(levelname)s] : %(message)s')}