Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] oeqa/utils/httpserver: connect up the request logging
@ 2023-01-26 17:30 Ross Burton
  2023-01-27 17:20 ` [OE-core] " Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Ross Burton @ 2023-01-26 17:30 UTC (permalink / raw)
  To: openembedded-core; +Cc: nd

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-27 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-26 17:30 [PATCH] oeqa/utils/httpserver: connect up the request logging Ross Burton
2023-01-27 17:20 ` [OE-core] " Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox