fix: rewrite log_message method of BaseHTTPRequestHandler to redirect log messages to mamonsu log
# -*- coding: utf-8 -*-
from mamonsu.lib.plugin import Plugin
-
from mamonsu.lib.const import API
from urllib.parse import urlparse as parse
from urllib.parse import parse_qs
from http.server import BaseHTTPRequestHandler, HTTPServer
-
-
-# rewrite log_request method of http lib to avoid getting log messages in console
-class QuietBaseHTTPRequestHandler(BaseHTTPRequestHandler):
- def log_request(self, code='-', size='-'):
- pass
+import logging
class AgentApi(Plugin):
@@ -38,11 +32,16 @@ class AgentApiHttpServer:
server.serve_forever()
-class AgentApiHandler(QuietBaseHTTPRequestHandler):
+class AgentApiHandler(BaseHTTPRequestHandler):
def __init__(self, config, *args):
self.sender = config.sender
- QuietBaseHTTPRequestHandler.__init__(self, *args)
+ self.log = logging.getLogger('AGENTAPI')
+ BaseHTTPRequestHandler.__init__(self, *args)
+
+ # rewrite log_message method of http lib to avoid getting log messages in console
+ def log_message(self, format, *args):
+ self.log.info(format, *args)
def _set_header(self):
self.send_response(200)
