Best Python code snippet using slash
log.py
Source:log.py
...194 log_path += ".br"195 else:196 raise InvalidConfiguraion("Unsupported compression method: {}".format(config.root.log.compression.algorithm))197 return log_path198 def _create_log_file_handler(self, log_path, bubble=False, filter=_slash_logs_filter, use_compression=False, use_rotation=False):199 kwargs = {"bubble": bubble, "filter": filter}200 if use_compression:201 if config.root.log.compression.algorithm == "gzip":202 handler_class = logbook.GZIPCompressionHandler203 elif config.root.log.compression.algorithm == "brotli":204 handler_class = logbook.BrotliCompressionHandler205 elif use_rotation:206 kwargs.update({"max_size": 4*1024**2, "backup_count": 1})207 handler_class = logbook.RotatingFileHandler208 elif config.root.log.colorize:209 handler_class = ColorizedFileHandler210 else:211 handler_class = logbook.FileHandler212 return handler_class(log_path, **kwargs)213 @contextmanager214 def _log_file_handler_context(self, subpath, symlink, bubble=False, filter=_slash_logs_filter, use_compression=False, use_rotation=False):215 if subpath is None or config.root.log.root is None:216 yield NoopHandler() if bubble else logbook.NullHandler(filter=filter)217 else:218 log_path = self._get_log_file_path(subpath, use_compression)219 handler = self._log_path_to_handler.get(log_path, None)220 if handler is not None:221 yield handler222 else:223 result = context.result224 ensure_containing_directory(log_path)225 if symlink:226 self._try_create_symlink(log_path, symlink)227 handler = self._create_log_file_handler(log_path, bubble=bubble, use_compression=use_compression,228 use_rotation=use_rotation, filter=filter)229 try:230 self._log_path_to_handler[log_path] = handler231 self._set_formatting(handler, config.root.log.format)232 with handling_exceptions():233 yield handler234 finally:235 handler.close()236 self._log_path_to_handler[log_path] = None237 with handling_exceptions(swallow=True):238 hooks.log_file_closed(path=log_path, result=result) # pylint: disable=no-member239 if config.root.log.cleanup.enabled and self._should_delete_log(result):240 with handling_exceptions(swallow=True):241 os.remove(log_path)...
logging.py
Source:logging.py
...13 return14 root_logger = logging.getLogger()15 root_logger.setLevel(logging.DEBUG)16 # Log into a log file.17 log_file_handler = _create_log_file_handler(config, script_name)18 root_logger.addHandler(log_file_handler)19 if config['logging'].getboolean('log_also_to_stderr'):20 # Log into the standard error.21 stderr_handler = _create_stderr_handler(config)22 root_logger.addHandler(stderr_handler)23def disable_logging():24 """Disables the logging facilities."""25 logging.disable(logging.CRITICAL)26def _create_log_file_handler(config, script_name):27 """Creates a handler for logging into a log file and returns it."""28 log_file_path = _get_log_file_for_script(config, script_name)29 log_file_handler = logging.FileHandler(log_file_path)30 log_file_formatter = logging.Formatter(config['logging']['entry_format'])31 log_file_handler.setFormatter(log_file_formatter)32 return log_file_handler33def _get_log_file_for_script(config, script_name):34 """Returns a path to the log file for the given script."""35 logs_dir = config['logging']['logs_dir']36 if not os.path.isabs(logs_dir):37 logs_dir = os.path.join(os.path.dirname(__file__), os.pardir, logs_dir)38 return os.path.join(logs_dir, script_name + config['logging']['extension'])39def _create_stderr_handler(config):40 """Creates a handler for the standard error output and returns it."""...
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!!