Best Python code snippet using lisa_python
logger_creator.py
Source:logger_creator.py
...12 self.cons_handler.setFormatter(self.create_handle_format(0))13 self.add_handlers([self.cons_handler])14 elif(self.num_handlers == 2):15 # Create Only FileHandler for file logging16 self.create_file_handler(self.file_name)17 self.file_handler.setFormatter(self.create_handle_format(1))18 self.add_handlers([self.file_handler])19 else:20 # Create Both Handlers21 self.create_console_handler()22 self.create_file_handler(self.file_name)23 self.cons_handler.setFormatter(self.create_handle_format(0))24 self.file_handler.setFormatter(self.create_handle_format(1))25 self.add_handlers([self.cons_handler, self.file_handler])26 def create_console_handler(self) -> None:27 self.cons_handler = logging.StreamHandler()28 self.cons_handler.setLevel(logging.DEBUG)29 def create_file_handler(self, file) -> None:30 self.file_handler = logging.FileHandler(filename=file)31 self.file_handler.setLevel(logging.ERROR)32 def create_handle_format(self, type: int = 0) -> logging.Formatter:33 if(type == 0):34 return logging.Formatter('%(name)s:%(levelname)s->%(message)s')35 elif(type == 1):36 return logging.Formatter('%(asctime)s:%(name)s:%(levelname)s->%(message)s')37 else:38 return logging.Formatter('%(levelname)s->%(message)s')39 def add_handlers(self, handle_list: list) -> None:40 for handle in handle_list:41 self.logger.addHandler(handle)42 def get_default_logger(self) -> logging.Logger:43 # Run create_handlers...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!