Best Python code snippet using testcontainers-python_python
log.py
Source:log.py
...58 'tag': tag,59 'rid': str(uuid.uuid4())60 }61 logger = self.logger_adapter_cls(self.logger, context)62 self.setup_logger(f, logger, context, args, kwargs)63 filtered_args = self._filter_args(args, args_to_skip_mask)64 filtered_kwargs = self._filter_kwargs(kwargs, args_to_skip)65 logger.info('Method {} called'.format(fname), extra={66 'params': filtered_args or filtered_kwargs67 })68 try:69 result = f(*args, **kwargs)70 result_to_log = result71 if response_mapper:72 result_to_log = response_mapper(result)73 logger.info('OK', extra={74 'response': result_to_log75 })76 except Exception:77 logger.exception('Internal error!')78 raise79 finally:80 # used to collect metrics by method names81 logger.info('Execution time', extra={82 'time': time.time() - start_time83 })84 return result85 functools.update_wrapper(wrapper, f)86 return wrapper87 return decorator88 @staticmethod89 def _get_func_name(f):90 if hasattr(f, 'im_func'):91 f = getattr(f, 'im_func')92 return f.__name__93 def _filter_args(self, args, skip_mask):94 if self.strip_self:95 args = args[1:]96 if not skip_mask:97 return args98 return [99 arg if skip_mask[i] else 'skipped'100 for i, arg in enumerate(args)101 ]102 def _filter_kwargs(self, kwargs, args_to_skip):103 if self.strip_self:104 kwargs.pop('self', None)105 if not args_to_skip:106 return kwargs107 return {108 k: v for k, v in kwargs.items()109 if k not in args_to_skip110 }111def build_flask_decorator(**kwargs):112 """113 Flask uses thread local global variables to handle context passing.114 This builder assumes usage of `flask.g` variable to get context from115 and to set logger to.116 It assumes that context is stored as `g.context` attribute,117 and it sets logger to `g.logger` attribute.118 :param kwargs: kwargs to pass to LoggedDecorator constructor.119 :return: `LoggedDecorator`120 """121 from flask import g122 def setup_logger(f, logger, context, args, kwargs):123 context.update(g.get('context', {}))124 setattr(g, 'logger', logger)125 kwargs['setup_logger'] = setup_logger126 return LoggedDecorator(**kwargs)127def build_instance_method_decorator(**kwargs):128 """129 When instance used - context and logger can be stored on it.130 This builder assumes that context available as `self.context`131 and sets logger to `self.logger`.132 :param kwargs: kwargs to pass to LoggedDecorator constructor.133 :return: `LoggedDecorator`134 """135 def setup_logger(f, logger, context, args, kwargs):136 self = args[0]137 context.update(getattr(self, 'context', {}))138 self.logger = logger139 kwargs['setup_logger'] = setup_logger140 kwargs['strip_self'] = True141 return LoggedDecorator(**kwargs)142def response_to_len_mapper(response):143 """Return only length of the response."""144 return 'response length is {}'.format(len(response))145def empty_mapper(response):146 """Return only 'Ok' message."""...
__init__.py
Source:__init__.py
...27import resource28def setup_all():29 from pritunl import logger30 setup_local()31 setup_logger()32 try:33 setup_clean()34 setup_temp_path()35 setup_signal_handler()36 setup_vault()37 setup_server()38 setup_mongo()39 setup_settings()40 setup_boto_conf()41 setup_public_ip()42 setup_host()43 setup_cache()44 setup_server_listeners()45 setup_dns()46 setup_monitoring()47 setup_poolers()48 setup_host_fix()49 setup_subscription()50 setup_ndppd()51 setup_runners()52 setup_handlers()53 setup_check()54 setup_plugins()55 setup_demo()56 soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)57 if soft < 25000 or hard < 25000:58 logger.warning(59 'Open file ulimit is lower then recommended',60 'setup',61 )62 except:63 logger.exception('Pritunl setup failed', 'setup')64 set_global_interrupt()65 raise66def setup_db():67 setup_local()68 try:69 setup_logger()70 setup_mongo()71 except:72 from pritunl import logger73 logger.exception('Pritunl setup failed', 'setup')74 raise75def setup_db_host():76 setup_local()77 try:78 setup_logger()79 setup_mongo()80 setup_host()81 except:82 from pritunl import logger83 logger.exception('Pritunl setup failed', 'setup')84 raise85def setup_loc():86 setup_local()87 try:88 setup_logger()89 except:90 from pritunl import logger91 logger.exception('Pritunl setup failed', 'setup')...
loggers.py
Source:loggers.py
...7, 'memory':False8, 'tourney':False9, 'mcts':False10, 'model': False}11logger_mcts = setup_logger('logger_mcts', run_folder + 'logs/logger_mcts.log')12logger_mcts.disabled = LOGGER_DISABLED['mcts']13logger_main = setup_logger('logger_main', run_folder + 'logs/logger_main.log')14logger_main.disabled = LOGGER_DISABLED['main']15logger_tourney = setup_logger('logger_tourney', run_folder + 'logs/logger_tourney.log')16logger_tourney.disabled = LOGGER_DISABLED['tourney']17logger_memory = setup_logger('logger_memory', run_folder + 'logs/logger_memory.log')18logger_memory.disabled = LOGGER_DISABLED['memory']19logger_model = setup_logger('logger_model', run_folder + 'logs/logger_model.log')20logger_model.disabled = LOGGER_DISABLED['model']...
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!!