Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Ross Burton <ross.burton@arm.com>
To: openembedded-core@lists.openembedded.org
Cc: nd@arm.com
Subject: [PATCH] oeqa/utils/httpserver: connect up the request logging
Date: Thu, 26 Jan 2023 17:30:48 +0000	[thread overview]
Message-ID: <20230126173048.1534444-1-ross.burton@arm.com> (raw)

Call logger.info() in the log_message handler so that we get request
logging, and hopefully even error messages.

Create a child logger to be neat and compartmentalise the logging.

Add a __main__ entrypoint so this class can be exercised outside of oeqa.

Remove unused traceback import.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/lib/oeqa/utils/httpserver.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py
index 8ce1dd42f49..b478172ed76 100644
--- a/meta/lib/oeqa/utils/httpserver.py
+++ b/meta/lib/oeqa/utils/httpserver.py
@@ -7,7 +7,6 @@
 import http.server
 import multiprocessing
 import os
-import traceback
 import signal
 from socketserver import ThreadingMixIn
 
@@ -15,20 +14,21 @@ class HTTPServer(ThreadingMixIn, http.server.HTTPServer):
 
     def server_start(self, root_dir, logger):
         os.chdir(root_dir)
+        self.logger = logger
         self.serve_forever()
 
 class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
 
     def log_message(self, format_str, *args):
-        pass
+        self.server.logger.info(format_str, *args)
 
-class HTTPService(object):
+class HTTPService:
 
     def __init__(self, root_dir, host='', port=0, logger=None):
         self.root_dir = root_dir
         self.host = host
         self.port = port
-        self.logger = logger
+        self.logger = logger.getChild("HTTPService")
 
     def start(self):
         if not os.path.exists(self.root_dir):
@@ -49,7 +49,7 @@ class HTTPService(object):
         signal.signal(signal.SIGTERM, orig)
 
         if self.logger:
-            self.logger.info("Started HTTPService on %s:%s" % (self.host, self.port))
+            self.logger.info("Started HTTPService for %s on %s:%s" % (self.root_dir, self.host, self.port))
 
 
     def stop(self):
@@ -61,3 +61,10 @@ class HTTPService(object):
         if self.logger:
             self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port))
 
+if __name__ == "__main__":
+    import sys, logging
+
+    logger = logging.getLogger(__name__)
+    logging.basicConfig(level=logging.DEBUG)
+    httpd = HTTPService(sys.argv[1], port=8888, logger=logger)
+    httpd.start()
-- 
2.34.1



             reply	other threads:[~2023-01-26 17:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 17:30 Ross Burton [this message]
2023-01-27 17:20 ` [OE-core] [PATCH] oeqa/utils/httpserver: connect up the request logging Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230126173048.1534444-1-ross.burton@arm.com \
    --to=ross.burton@arm.com \
    --cc=nd@arm.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox