aws-auto-remediate icon indicating copy to clipboard operation
aws-auto-remediate copied to clipboard

Use exc_info kwarg for logging.log()

Open jihygk opened this issue 5 years ago • 1 comments

https://docs.python.org/3/library/logging.html#logging.Logger.debug

Instead of, for example,

https://github.com/servian/aws-auto-remediate/blob/b4ea0b0938d358b607716285b0ba641127d954ed/auto_remediate/lambda_handler.py#L163-L167

The following achieves the same:

self.logging.error( 
         f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'.",
         exc_info=True
     ) 

jihygk avatar May 24 '19 11:05 jihygk

@jihygk I tried implementing this but unfortunately it prints and entire stack trace (which dirties up the logs) which is what I got around by only taking the second tupple sys.exc_info()[1]. You can override the behaviour by implementing formatException(exc_info) but it's more complex.

mlevit avatar May 26 '19 00:05 mlevit