Add option log_return_value.

This commit is contained in:
voussoir 2021-10-09 17:56:31 -07:00
parent 531424c8c1
commit 87fbede7d5
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -220,7 +220,7 @@ def get_level_by_argv(argv):
return (argv, level)
def main_decorator(subject, **kwargs):
def main_decorator(subject, *, log_return_value=True, **kwargs):
'''
Add this decorator to your application's main function to automatically
wrap it in a main_log_context and log the final return value. For example:
@ -255,7 +255,8 @@ def main_decorator(subject, **kwargs):
with context:
status = main(argv)
log.info('Program finished, returned %s.', status)
if log_return_value:
log.info('Program finished, returned %s.', status)
return status
return wrapped
return wrapper