FAQ | This is a LIVE service | Changelog

Utility to log exception with bound logger

Description

Decorator and exception wrapper to log bound logger...

E.g.

@ucam_observe.log_exception
def some_function(valid_request):

  bound_logger = logger.bind(some="value")
  ...
  
  if not valid_request:
    # This exception will be caught by @ucam_observe.log_exception, the passed in exception will logged using the bound logger (so will have some="value") and then the passed in argument will be raised
    raise ucam_observe.LogWrapper(ValidationError("this fields needs to be..."), bound_logger)


  if other_issue:
    # This will also be caught and logged but not using the bound logger 
    raise ValidationError("this fields needs to be...")

Also make as context manager.

Further details

Task list

Acceptance criteria

Edited by Ed Kirk