Remove *args, force use of named arguments.

master
voussoir 2021-10-09 17:55:52 -07:00
parent c87fc584da
commit 531424c8c1
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 5 additions and 5 deletions

View File

@ -220,7 +220,7 @@ def get_level_by_argv(argv):
return (argv, level) return (argv, level)
def main_decorator(subject, *args, **kwargs): def main_decorator(subject, **kwargs):
''' '''
Add this decorator to your application's main function to automatically 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: wrap it in a main_log_context and log the final return value. For example:
@ -241,7 +241,7 @@ def main_decorator(subject, *args, **kwargs):
def wrapper(main): def wrapper(main):
def wrapped(argv): def wrapped(argv):
(argv, level) = get_level_by_argv(argv) (argv, level) = get_level_by_argv(argv)
context = main_log_context(subject, level, *args, **kwargs) context = main_log_context(subject, level, **kwargs)
# We need to call basic_config so that operatornotify's logs have # We need to call basic_config so that operatornotify's logs have
# somewhere to go. We do this only during wrapped, not before, so # somewhere to go. We do this only during wrapped, not before, so
@ -260,7 +260,7 @@ def main_decorator(subject, *args, **kwargs):
return wrapped return wrapped
return wrapper return wrapper
def main_log_context(subject, level, *args, **kwargs): def main_log_context(subject, level, **kwargs):
''' '''
Returns a context manager with which you'll wrap your function. Returns a context manager with which you'll wrap your function.
Will be nullcontext if the level is None (user did not opt in). Will be nullcontext if the level is None (user did not opt in).
@ -271,14 +271,14 @@ def main_log_context(subject, level, *args, **kwargs):
that kills your function. that kills your function.
3. Results are sent at the end of the context, when your function returns. 3. Results are sent at the end of the context, when your function returns.
Additional *args, **kwargs go to LogHandler init, so you can Additional **kwargs go to LogHandler init, so you can
pass notify_every_line, etc. pass notify_every_line, etc.
''' '''
if level is None: if level is None:
return contextlib.nullcontext() return contextlib.nullcontext()
log = vlogging.getLogger() log = vlogging.getLogger()
handler = LogHandler(subject, *args, **kwargs) handler = LogHandler(subject, **kwargs)
handler.setLevel(level) handler.setLevel(level)
handler.setFormatter(vlogging.Formatter('{levelname}:{name}:{message}', style='{')) handler.setFormatter(vlogging.Formatter('{levelname}:{name}:{message}', style='{'))
context = LogHandlerContext(log, handler) context = LogHandlerContext(log, handler)