docstring for log

This commit is contained in:
Will McGugan
2022-08-25 09:27:30 +01:00
parent 4a6b1996de
commit 8f51d2a52e
3 changed files with 39 additions and 8 deletions

View File

@@ -110,9 +110,33 @@ class MessagePump(metaclass=MessagePumpMeta):
def is_running(self) -> bool:
return self._running
def log(self, *args, **kwargs) -> None:
"""Write to logs or devtools."""
return self.app.log(*args, **kwargs, _textual_calling_frame=inspect.stack()[1])
def log(
self,
*args: Any,
verbosity: int = 1,
**kwargs,
) -> None:
"""Write to logs or devtools.
Positional args will logged. Keyword args will be prefixed with the key.
Example:
```python
data = [1,2,3]
self.log("Hello, World", state=data)
self.log(self.tree)
self.log(locals())
```
Args:
verbosity (int, optional): Verbosity level 0-3. Defaults to 1.
"""
return self.app.log(
*args,
**kwargs,
verbosity=verbosity,
_textual_calling_frame=inspect.stack()[1],
)
def _attach(self, parent: MessagePump) -> None:
"""Set the parent, and therefore attach this node to the tree.