Skip to content

Commit 8f524bf

Browse files
committed
fix: rewrite log_message method of BaseHTTPRequestHandler to redirect log messages to mamonsu log
1 parent f257769 commit 8f524bf

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

mamonsu/tools/agent/agent.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# -*- coding: utf-8 -*-
22
from mamonsu.lib.plugin import Plugin
3-
43
from mamonsu.lib.const import API
54

65
from urllib.parse import urlparse as parse
76
from urllib.parse import parse_qs
87
from http.server import BaseHTTPRequestHandler, HTTPServer
9-
10-
11-
# rewrite log_request method of http lib to avoid getting log messages in console
12-
class QuietBaseHTTPRequestHandler(BaseHTTPRequestHandler):
13-
def log_request(self, code='-', size='-'):
14-
pass
8+
import logging
159

1610

1711
class AgentApi(Plugin):
@@ -38,11 +32,16 @@ def handler(*args):
3832
server.serve_forever()
3933

4034

41-
class AgentApiHandler(QuietBaseHTTPRequestHandler):
35+
class AgentApiHandler(BaseHTTPRequestHandler):
4236

4337
def __init__(self, config, *args):
4438
self.sender = config.sender
45-
QuietBaseHTTPRequestHandler.__init__(self, *args)
39+
self.log = logging.getLogger('AGENTAPI')
40+
BaseHTTPRequestHandler.__init__(self, *args)
41+
42+
# rewrite log_message method of http lib to avoid getting log messages in console
43+
def log_message(self, format, *args):
44+
self.log.info(format, *args)
4645

4746
def _set_header(self):
4847
self.send_response(200)

0 commit comments

Comments
 (0)