Add support for kwargs logging

This commit is contained in:
Darren Burns
2022-04-11 16:21:43 +01:00
parent f9b1d86330
commit 671554e648
3 changed files with 21 additions and 19 deletions

View File

@@ -38,7 +38,7 @@ class Timer:
name: str | None = None,
callback: TimerCallback | None = None,
repeat: int | None = None,
skip: bool = True,
skip: bool = False,
pause: bool = False,
) -> None:
"""A class to send timer-based events.

View File

@@ -220,29 +220,30 @@ class App(DOMNode):
output = ""
try:
output = f" ".join(str(arg) for arg in objects)
if self.log_file and verbosity <= self.log_verbosity:
if kwargs:
key_values = " ".join(
f"{key}={value}" for key, value in kwargs.items()
if kwargs:
key_values = " ".join(f"{key}={value}" for key, value in kwargs.items())
output = " ".join((output, key_values))
if not caller:
caller = inspect.stack()[1]
calling_path = caller.filename
calling_lineno = caller.lineno
if self.devtools.is_connected and verbosity <= self.log_verbosity:
if len(objects) > 1 or len(kwargs) >= 1 and output:
self.devtools.log(output, path=calling_path, lineno=calling_lineno)
else:
self.devtools.log(
*objects, path=calling_path, lineno=calling_lineno
)
output = " ".join((output, key_values))
if self.log_file and verbosity <= self.log_verbosity:
self.log_file.write(output + "\n")
self.log_file.flush()
except Exception:
pass
if not caller:
caller = inspect.stack()[1]
calling_path = caller.filename
calling_lineno = caller.lineno
if self.devtools.is_connected and verbosity <= self.log_verbosity:
if len(objects) > 1 and output:
self.devtools.log(output, path=calling_path, lineno=calling_lineno)
else:
self.devtools.log(*objects, path=calling_path, lineno=calling_lineno)
def bind(
self,
keys: str,

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import inspect
from asyncio import CancelledError
from asyncio import PriorityQueue, QueueEmpty, Task
from functools import partial, total_ordering
@@ -86,7 +87,7 @@ class MessagePump:
return self._running
def log(self, *args, **kwargs) -> None:
return self.app.log(*args, **kwargs)
return self.app.log(*args, **kwargs, caller=inspect.stack()[1])
def set_parent(self, parent: MessagePump) -> None:
self._parent = parent