diff --git a/moonraker/app.py b/moonraker/app.py index a85b572..f1d6bc3 100644 --- a/moonraker/app.py +++ b/moonraker/app.py @@ -149,9 +149,7 @@ class MoonrakerApp: mimetypes.add_type('text/plain', '.gcode') mimetypes.add_type('text/plain', '.cfg') - self.debug = config.getboolean('enable_debug_logging', False) - log_level = logging.DEBUG if self.debug else logging.INFO - logging.getLogger().setLevel(log_level) + self.debug = self.server.is_debug_enabled() app_args: Dict[str, Any] = { 'serve_traceback': self.debug, 'websocket_ping_interval': 10, @@ -544,6 +542,14 @@ class DynamicRequestHandler(AuthorizedRequestHandler): args[key] = value return args + def _log_debug(self, header: str, args: Dict[str, Any]) -> None: + if self.server.is_debug_enabled(): + if self.request.path.startswith('/access'): + resp = {key: "" for key in args} + else: + resp = args + logging.debug(f"{header}::{resp}") + async def get(self, *args, **kwargs) -> None: await self._process_http_request() @@ -579,7 +585,7 @@ class DynamicRequestHandler(AuthorizedRequestHandler): conn = self.get_associated_websocket() args = self.parse_args() req = f"{self.request.method} {self.request.path}" - logging.debug(f"HTTP Request::{req}::{args}") + self._log_debug(f"HTTP Request::{req}", args) try: result = await self._do_request(args, conn) except ServerError as e: @@ -587,7 +593,7 @@ class DynamicRequestHandler(AuthorizedRequestHandler): e.status_code, str(e)) from e if self.wrap_result: result = {'result': result} - logging.debug(f"HTTP Response::{req}::{result}") + self._log_debug(f"HTTP Response::{req}", result) self.finish(result) class FileRequestHandler(AuthorizedFileHandler): diff --git a/moonraker/eventloop.py b/moonraker/eventloop.py index 6730233..972b8db 100644 --- a/moonraker/eventloop.py +++ b/moonraker/eventloop.py @@ -38,6 +38,7 @@ class EventLoop: self.create_future = self.aioloop.create_future self.create_task = self.aioloop.create_task self.call_at = self.aioloop.call_at + self.set_debug = self.aioloop.set_debug def register_callback(self, callback: FlexCallback, diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 307c522..703dd4a 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -88,6 +88,13 @@ class Server: self.ssl_port: int = config.getint('ssl_port', 7130) self.exit_reason: str = "" + # Configure Debug Logging + self.debug = config.getboolean('enable_debug_logging', False) + asyncio_debug = config.getboolean('enable_asyncio_debug', False) + log_level = logging.DEBUG if self.debug else logging.INFO + logging.getLogger().setLevel(log_level) + self.event_loop.set_debug(asyncio_debug) + # Event initialization self.events: Dict[str, List[FlexCallback]] = {} @@ -160,6 +167,9 @@ class Server: def is_running(self) -> bool: return self.server_running + def is_debug_enabled(self) -> bool: + return self.debug + async def _start_server(self): optional_comps: List[Coroutine] = [] for name, component in self.components.items():