app: initialize all logging options

Moving log level init to the app module and have it explicitly set the level.  This allows the logging level to be toggled with a server restart.  Default debug logging to False.

When debug logging is disabled do not  log HTTP requests.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-06 07:33:10 -05:00
parent d108334c37
commit 438ffece72
2 changed files with 12 additions and 11 deletions

View File

@ -90,20 +90,24 @@ class MoonrakerApp:
mimetypes.add_type('text/plain', '.log')
mimetypes.add_type('text/plain', '.gcode')
mimetypes.add_type('text/plain', '.cfg')
debug = config.getboolean('enable_debug_logging', True)
debug = config.getboolean('enable_debug_logging', False)
log_level = logging.DEBUG if debug else logging.INFO
logging.getLogger().setLevel(log_level)
app_args = {
'serve_traceback': debug,
'websocket_ping_interval': 10,
'websocket_ping_timeout': 30,
'parent': self
}
if not debug:
app_args['log_function'] = lambda hdlr: None
# Set up HTTP only requests
self.mutable_router = MutableRouter(self)
app_handlers = [
(AnyMatches(), self.mutable_router),
(r"/websocket", WebSocket)]
self.app = tornado.web.Application(
app_handlers,
serve_traceback=debug,
websocket_ping_interval=10,
websocket_ping_timeout=30,
parent=self)
self.app = tornado.web.Application(app_handlers, **app_args)
self.get_handler_delegate = self.app.get_handler_delegate
# Register handlers

View File

@ -134,9 +134,6 @@ def get_configuration(server, system_args):
except Exception:
pass
if server_cfg.getboolean('enable_debug_logging', True):
logging.getLogger().setLevel(logging.DEBUG)
config['system_args'] = {
'configfile': system_args.configfile,
'logfile': system_args.logfile,