aboutsummaryrefslogtreecommitdiff
path: root/scripts/qmp
diff options
context:
space:
mode:
authorEduardo Habkost <ehabkost@redhat.com>2017-10-05 14:20:12 -0300
committerEduardo Habkost <ehabkost@redhat.com>2017-10-11 15:15:17 -0300
commit091776545f759f379fa9ae5b67ce5b2a6153a010 (patch)
tree1d3fba860f1bc2839e65aa4966f69c45e38932e1 /scripts/qmp
parent8af09b8001301e6bb085a23fc029da94e0725c1c (diff)
scripts: Remove debug parameter from QEMUMonitorProtocol
Use logging module for the QMP debug messages. The only scripts that set debug=True are iotests.py and guestperf/engine.py, and they already call logging.basicConfig() to set up logging. Scripts that don't configure logging are safe as long as they don't need debugging output, because debug messages don't trigger the "No handlers could be found for logger" message from the Python logging module. Scripts that already configure logging but don't use debug=True (e.g. scripts/vm/basevm.py) will get QMP debugging enabled for free. Cc: "Alex Bennée" <alex.bennee@linaro.org> Cc: Fam Zheng <famz@redhat.com> Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <20171005172013.3098-3-ehabkost@redhat.com> Reviewed-by: Lukáš Doktor <ldoktor@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'scripts/qmp')
-rw-r--r--scripts/qmp/qmp.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py
index ef12e8a1a0..07c9632e9e 100644
--- a/scripts/qmp/qmp.py
+++ b/scripts/qmp/qmp.py
@@ -11,7 +11,7 @@
import json
import errno
import socket
-import sys
+import logging
class QMPError(Exception):
@@ -32,12 +32,14 @@ class QMPTimeoutError(QMPError):
class QEMUMonitorProtocol(object):
+ #: Logger object for debugging messages
+ logger = logging.getLogger('QMP')
#: Socket's error class
error = socket.error
#: Socket's timeout
timeout = socket.timeout
- def __init__(self, address, server=False, debug=False):
+ def __init__(self, address, server=False):
"""
Create a QEMUMonitorProtocol class.
@@ -51,7 +53,6 @@ class QEMUMonitorProtocol(object):
"""
self.__events = []
self.__address = address
- self._debug = debug
self.__sock = self.__get_sock()
self.__sockfile = None
if server:
@@ -83,8 +84,7 @@ class QEMUMonitorProtocol(object):
return
resp = json.loads(data)
if 'event' in resp:
- if self._debug:
- print >>sys.stderr, "QMP:<<< %s" % resp
+ self.logger.debug("<<< %s", resp)
self.__events.append(resp)
if not only_event:
continue
@@ -164,8 +164,7 @@ class QEMUMonitorProtocol(object):
@return QMP response as a Python dict or None if the connection has
been closed
"""
- if self._debug:
- print >>sys.stderr, "QMP:>>> %s" % qmp_cmd
+ self.logger.debug(">>> %s", qmp_cmd)
try:
self.__sock.sendall(json.dumps(qmp_cmd))
except socket.error as err:
@@ -173,8 +172,7 @@ class QEMUMonitorProtocol(object):
return
raise socket.error(err)
resp = self.__json_read()
- if self._debug:
- print >>sys.stderr, "QMP:<<< %s" % resp
+ self.logger.debug("<<< %s", resp)
return resp
def cmd(self, name, args=None, cmd_id=None):