Best Python code snippet using autotest_python
loggers.py
Source: loggers.py
1# Configuring all Loggers2import sys3from defs import SYSTEM_LOG4import logging5# Dict of all instantiated loggers6loggers = {}7# Main System Logger8class SystemLogger:9 def __init__(self, logger_name: str, add_file_handler: bool = True, add_stream_handler: bool = True):10 self.logger_name = logger_name11 # If logger exists, return existing logger12 if loggers.get(self.logger_name):13 self.logger = loggers.get(self.logger_name)14 # Otherwise create new logger15 else:16 # input params17 self.add_file_handler = add_file_handler18 self.add_stream_handler = add_stream_handler19 # Define log formatter20 self.formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s')21 # Define handlers22 self.file_handler = logging.FileHandler(SYSTEM_LOG, mode='a')23 self.file_handler.setFormatter(self.formatter)24 self.stream_handler = logging.StreamHandler(sys.stdout)25 self.stream_handler.setFormatter(self.formatter)26 # Get logger27 self.logger = self.getLogger()28 # Set default logging level to DEBUG29 self.logger.setLevel(logging.DEBUG)30 # Save to loggers dict31 loggers[self.logger_name] = self.logger32 # Function to get logger33 def getLogger(self) -> logging.Logger:34 logger = logging.getLogger(name=self.logger_name)35 self.addHandlers(logger)36 return logger37 # Function to add handlers to logger38 def addHandlers(self, logger: logging.Logger) -> logging.Logger:39 # Add handler iff logger is parent (i.e. not child) and requested40 if ("." not in self.logger_name) and self.add_file_handler:41 logger.addHandler(self.file_handler)42 if ("." not in self.logger_name) and self.add_stream_handler:43 logger.addHandler(self.stream_handler)...
log.py
Source: log.py
...3import logging4LOG_FORMAT = "%(asctime)s [%(levelname)s - %(module)s] %(message)s"5TIME_FORMAT = "%Y-%m-%d %H:%M:%S"6FORMATTER = logging.Formatter( LOG_FORMAT, TIME_FORMAT )7def add_stream_handler( logger, stream=sys.stdout, log_level=logging.INFO ):8 # Set up a simple Stream handler9 stream_handler = logging.StreamHandler( stream=stream )10 stream_handler.setFormatter( FORMATTER )11 stream_handler.setLevel( log_level )12 logger.addHandler( stream_handler )13def add_file_handler( logger, log_file='hla_pipeline.log', log_level=logging.INFO ):14 # Set a second handler for the log file15 file_handler = logging.FileHandler( log_file )16 file_handler.setFormatter( FORMATTER )17 file_handler.setLevel( log_level )18 logger.addHandler( file_handler )19def initialize_logger( logger, stream=None, log_file=None, debug=False):20 if debug:21 log_level = logging.DEBUG22 else:23 log_level = logging.INFO24 logger.setLevel( log_level )25 if stream:26 add_stream_handler( logger, stream=stream, log_level=log_level )27 else:28 add_stream_handler( logger, log_level=log_level )29 if log_file:30 add_file_handler( logger, log_file=log_file, log_level=log_level )31 else:32 add_file_handler( logger, log_level=log_level )...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!