From 9fa2e1501e5726da7f794ef31d5b910848525349 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 13 Jan 2010 12:08:03 +0100 Subject: [PATCH] Improve logging for workerpool tasks by providing __repr__ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before it would log something like βstarting task (<ganeti.http.client._HttpClientPendingRequest object at 0x2aaaad176790>,)β, which isn't really useful for debugging. Now it'll log β[β¦] <ganeti.http.client._HttpClientPendingRequest req=<ganeti.http.client.HttpClientRequest 172.24.x.y:1811 PUT /node_info at 0x2aaaaab7ed10> at 0x2aaaaab823d0>β. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/http/client.py | 14 ++++++++++++++ lib/jqueue.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/lib/http/client.py b/lib/http/client.py index d32eb5be6..5ca76a163 100644 --- a/lib/http/client.py +++ b/lib/http/client.py @@ -95,6 +95,14 @@ class HttpClientRequest(object): self.resp_headers = None self.resp_body = None + def __repr__(self): + status = ["%s.%s" % (self.__class__.__module__, self.__class__.__name__), + "%s:%s" % (self.host, self.port), + self.method, + self.path] + + return "<%s at %#x>" % (" ".join(status), id(self)) + class _HttpClientToServerMessageWriter(http.HttpMessageWriter): pass @@ -328,6 +336,12 @@ class _HttpClientPendingRequest(object): # Thread synchronization self.done = threading.Event() + def __repr__(self): + status = ["%s.%s" % (self.__class__.__module__, self.__class__.__name__), + "req=%r" % self.request] + + return "<%s at %#x>" % (" ".join(status), id(self)) + class HttpClientWorker(workerpool.BaseWorker): """HTTP client worker class. diff --git a/lib/jqueue.py b/lib/jqueue.py index f7e05575f..f989ef839 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -190,6 +190,13 @@ class _QueuedJob(object): # Condition to wait for changes self.change = threading.Condition(self.queue._lock) + def __repr__(self): + status = ["%s.%s" % (self.__class__.__module__, self.__class__.__name__), + "id=%s" % self.id, + "ops=%s" % ",".join([op.input.Summary() for op in self.ops])] + + return "<%s at %#x>" % (" ".join(status), id(self)) + @classmethod def Restore(cls, queue, state): """Restore a _QueuedJob from serialized state: -- GitLab