diff options
| author | John Snow <jsnow@redhat.com> | 2022-07-22 16:30:05 -0400 |
|---|---|---|
| committer | John Snow <jsnow@redhat.com> | 2025-09-15 14:36:01 -0400 |
| commit | 094ded5227dc4e8dde2c78a9788bf6c90771ad85 (patch) | |
| tree | 643eb84068a9ce28c1d53f09c50be2145fc44589 /python/qemu | |
| parent | 1e343714bfc06cc982e68a290f3809117d6dfcd0 (diff) | |
| download | focaccia-qemu-094ded5227dc4e8dde2c78a9788bf6c90771ad85.tar.gz focaccia-qemu-094ded5227dc4e8dde2c78a9788bf6c90771ad85.zip | |
python: backport 'protocol: adjust logging name when changing client name'
The client name is mutable, so the logging name should also change to reflect it when it changes. Signed-off-by: John Snow <jsnow@redhat.com> cherry picked from commit python-qemu-qmp@e10b73c633ce138ba30bc8beccd2ab31989eaf3d Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'python/qemu')
| -rw-r--r-- | python/qemu/qmp/protocol.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/python/qemu/qmp/protocol.py b/python/qemu/qmp/protocol.py index 86e588881b..ec4762c567 100644 --- a/python/qemu/qmp/protocol.py +++ b/python/qemu/qmp/protocol.py @@ -217,10 +217,8 @@ class AsyncProtocol(Generic[T]): # ------------------------- def __init__(self, name: Optional[str] = None) -> None: - #: The nickname for this connection, if any. - self.name: Optional[str] = name - if self.name is not None: - self.logger = self.logger.getChild(self.name) + self._name: Optional[str] + self.name = name # stream I/O self._reader: Optional[StreamReader] = None @@ -257,6 +255,24 @@ class AsyncProtocol(Generic[T]): tokens.append(f"runstate={self.runstate.name}") return f"<{cls_name} {' '.join(tokens)}>" + @property + def name(self) -> Optional[str]: + """ + The nickname for this connection, if any. + + This name is used for differentiating instances in debug output. + """ + return self._name + + @name.setter + def name(self, name: Optional[str]) -> None: + logger = logging.getLogger(__name__) + if name: + self.logger = logger.getChild(name) + else: + self.logger = logger + self._name = name + @property # @upper_half def runstate(self) -> Runstate: """The current `Runstate` of the connection.""" |