MCPcopy Index your code
hub / github.com/StackStorm/st2 / decorate_log_method

Function decorate_log_method

st2common/st2common/log.py:148–168  ·  view source on GitHub ↗
(func)

Source from the content-addressed store, hash-verified

146
147
148def decorate_log_method(func):
149 @wraps(func)
150 def func_wrapper(*args, **kwargs):
151 # Prefix extra keys with underscore
152 if "extra" in kwargs:
153 kwargs["extra"] = prefix_dict_keys(dictionary=kwargs["extra"], prefix="_")
154
155 try:
156 return func(*args, **kwargs)
157 except TypeError as e:
158 # In some version of Python 2.7, logger.exception doesn't take any kwargs so we need
159 # this hack :/
160 # See:
161 # - https://docs.python.org/release/2.7.3/library/logging.html#logging.Logger.exception
162 # - https://docs.python.org/release/2.7.7/library/logging.html#logging.Logger.exception
163 if "got an unexpected keyword argument 'extra'" in six.text_type(e):
164 kwargs.pop("extra", None)
165 return func(*args, **kwargs)
166 raise e
167
168 return func_wrapper
169
170
171def decorate_logger_methods(logger):

Callers 1

decorate_logger_methodsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected