Logger Helper

Logger Helper main classes and utility functions.

class logger_helper.LoggerHelper(logger, log_level)

Log calls to class methods and functions.

Create a new helper that writes to a specific logger.

Parameters:
  • logger (logging.Logger) – The logger to write to.
  • log_level (int) – The log level to log at. This should be one of the logging.XXXXX constants, for example logging.DEBUG.
call_log_format

str – The format string to use when formatting a call to a callable. The available tokens are:

  • callable - The name of the callable.
  • args - The arguments passed to the callable. The format of the arguments is defined in the argument_format property.
argument_format

str – The format of each argument. The available tokens are:

  • name - The name of the argument.
  • value - The value of the argument.
argument_separator

str – The separator to join the arguments together with.

return_log_format

str – The format to log the return with. The available tokens are:

  • callable - The name of the callable.
  • return_value - The return value (after it’s been run through repr).
exception_log_format

str – The format to log exceptions with. The available tokens are:

  • callable - The name of the callable.
  • name - The name of the exception.
  • message - The exception message.
__call__(obj)

Wrap the class methods or functions in our decorator.

Raises:TypeError – When the object isn’t a class or function.
Returns:The fully wrapped class or function.
cls(cls)

Wrap a classes methods (that don’t start and end with __).

Parameters:cls – The class to wrap.
Returns:A copy of the given class with all of it’s methods wrapped.
Return type:cls
func(function)

Wrap a function.

Parameters:function – The function to wrap.
Returns:A wrapped copy of the given function.
Return type:function
meth(method)

Wrap a method belonging to a class.

Returns:A wrapped copy of the fiven method.
Return type:method
mod(mod, symbols=None)

Wrap an entire module’s classes and functions.

Parameters:
  • mod (module) – The module to wrap.
  • symbols (list) – If this is specified, only the symbols (classes/functions) listed will be wrapped. Each item in the list should be a string.
Returns:

Nothing is returned, the class is wrapped in place.

Return type:

None

logger_helper.get_callable_name(clbl)

Get the fully qualified name of a callable.

Parameters:clbl – The callable to get the name for.
Returns:A string representing the full path to the given callable.
Return type:str