Hi Eduardo
I'm already fixing it.

Thank you,

On Sun, Mar 15, 2020 at 5:39 PM Eduardo Habkost <ehabk...@redhat.com> wrote:

> On Thu, Mar 12, 2020 at 04:05:47PM +0200, Oksana Vohchana wrote:
> > QEMUMachine writes some messages to the default logger.
> > But it sometimes hard to read the output if we have requests to
> > more than one VM.
> > This patch adds a label to the logger in the debug mode.
> >
> > Signed-off-by: Oksana Vohchana <ovosh...@redhat.com>
> >
> > ---
> > v2:
> >  - Instead of shown the label in the message it provides the label
> >    only in the debug logger information
> > ---
> >  python/qemu/machine.py | 2 +-
> >  python/qemu/qmp.py     | 5 ++++-
> >  2 files changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> > index 183d8f3d38..d0aa774c1c 100644
> > --- a/python/qemu/machine.py
> > +++ b/python/qemu/machine.py
> > @@ -270,7 +270,7 @@ class QEMUMachine(object):
> >                  self._vm_monitor = os.path.join(self._sock_dir,
> >                                                  self._name +
> "-monitor.sock")
> >                  self._remove_files.append(self._vm_monitor)
> > -            self._qmp = qmp.QEMUMonitorProtocol(self._vm_monitor,
> server=True)
> > +            self._qmp = qmp.QEMUMonitorProtocol(self._vm_monitor,
> server=True, nickname=self._name)
> >
> >      def _post_launch(self):
> >          if self._qmp:
> > diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
> > index f40586eedd..d58b18c304 100644
> > --- a/python/qemu/qmp.py
> > +++ b/python/qemu/qmp.py
> > @@ -46,7 +46,7 @@ class QEMUMonitorProtocol:
> >      #: Logger object for debugging messages
> >      logger = logging.getLogger('QMP')
>
> This will create a single logger instance.
>
> >
> > -    def __init__(self, address, server=False):
> > +    def __init__(self, address, server=False, nickname=None):
> >          """
> >          Create a QEMUMonitorProtocol class.
> >
> > @@ -62,6 +62,7 @@ class QEMUMonitorProtocol:
> >          self.__address = address
> >          self.__sock = self.__get_sock()
> >          self.__sockfile = None
> > +        self._nickname = nickname
> >          if server:
> >              self.__sock.setsockopt(socket.SOL_SOCKET,
> socket.SO_REUSEADDR, 1)
> >              self.__sock.bind(self.__address)
> > @@ -188,6 +189,8 @@ class QEMUMonitorProtocol:
> >          @return QMP response as a Python dict or None if the connection
> has
> >                  been closed
> >          """
> > +        if self._nickname:
> > +            self.logger.name = 'QMP.{}'.format(self._nickname)
>
> This will change the name of that single instance and affect
> every single QEMUMonitorProtocol object.  Please don't do that.
>
> You can just do:
>
>     self.logger = logging.getLogger('QMP').getChild(self._nickname)
>
> at __init__().
>
>
> >          self.logger.debug(">>> %s", qmp_cmd)
> >          try:
> >              self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8'))
> > --
> > 2.21.1
> >
>
> --
> Eduardo
>
>

Reply via email to