Best Python code snippet using autotest_python
httpclient.py
Source:httpclient.py
...49 self.API_VERSION_HEADER: api_version.get_string(),50 'User-Agent': user_agent,51 'Accept': 'application/json',52 }53 self._add_log_handlers(http_log_debug)54 def _add_log_handlers(self, http_log_debug):55 self._logger = logging.getLogger(__name__)56 # check that handler hasn't already been added57 if http_log_debug and not self._logger.handlers:58 ch = logging.StreamHandler()59 ch._name = 'http_client_handler'60 self._logger.setLevel(logging.DEBUG)61 self._logger.addHandler(ch)62 if hasattr(requests, 'logging'):63 rql = requests.logging.getLogger(requests.__name__)64 rql.addHandler(ch)65 def _get_base_url(self, url):66 """Truncates url and returns transport, address, and port number."""67 base_url = '/'.join(url.split('/')[:3]) + '/'68 return base_url...
log_utils.py
Source:log_utils.py
...17 os.path.join(18 path_utils.PLUGIN_LOG_LOCATION,19 "_".join([plugin.name, str(plugin.id)]) + ".log")20 )21def _add_log_handlers(logger, logfile):22 """23 Add the file and stream handlers to a logger.24 :param logging.logger logger: the logger to configure25 :param str logfile: file to log to disk26 :returns: the rotating file handler, used for subprocess logging.27 :rtype: FileHandler28 """29 path_utils.ensure_file_exists(logfile)30 logger.setLevel(logging.INFO)31 fh = TimedRotatingFileHandler(logfile, when="midnight", backupCount=3)32 fh.setFormatter(logging.Formatter('%(asctime)s : %(levelname)s : %(message)s'))33 logger.addHandler(fh)34 logger.addHandler(_SH)35 return fh36### Define extra custom logging levels.37### Mostly used for fluff, but potentially usefull also for log tracking and management.38### We define BOOT and SHUTDOWN here.39BOOTUP = logging.ERROR + 140logging.addLevelName(BOOTUP, "BOOT")41def boot(self, message, *args, **kws): #pylint: disable=missing-docstring42 if self.isEnabledFor(BOOTUP):43 # Yes, logger takes its '*args' as 'args'.44 self._log(BOOTUP, message, args, **kws)45logging.Logger.boot = boot46SHUTDOWN = logging.ERROR + 247logging.addLevelName(SHUTDOWN, "SHUTDOWN")48def shutdown(self, message, *args, **kws): #pylint: disable=missing-docstring49 if self.isEnabledFor(SHUTDOWN):50 # Yes, logger takes its '*args' as 'args'.51 self._log(SHUTDOWN, message, args, **kws)52logging.Logger.shutdown = shutdown53path_utils.ensure_path_exists(path_utils.LOG_LOCATION)54path_utils.ensure_path_exists(path_utils.PLUGIN_LOG_LOCATION)55_SH = logging.StreamHandler(sys.stdout)56_SH.setFormatter(logging.Formatter('%(asctime)s : %(levelname)s : %(message)s'))57LOG = logging.getLogger("AIGIS")...
AigisLog.py
Source:AigisLog.py
...19 def __init__(self, plugin):20 super().__init__(self)21 self.log_file = _plugin_file_name(plugin)22 self.name = plugin.name23 fh = _add_log_handlers(self, self.log_file)24 if plugin.type == "external":25 self.filehandler = fh26 def tail(self):27 """28 Fetch the last 5 logs of a certain plugin.29 :returns: last 5 or fewer logs in the log file.30 :rtype: list31 """32 try:33 with open(self.log_file, 'r') as f:34 endlogs = deque(f, 5)35 return endlogs36 except IOError:37 LOG.warning("File %s does not exist. Cannot tail.", self.log_file)...
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!!