🔇 Make tornado.access less verbose for /api/printer
409 returns on this endpoint are common if the printer is not currently connected. Reduce log spam by rewriting such requests to INFO level, which by default won't get logged.
This commit is contained in:
1 parent
9df942c7c4
commit
3f60fa492b
3 files changed
+35
No files matched your search
@@ -557,6 +557,8 @@ def set_logging_config(config, debug, verbosity, uncaught_logger, uncaught_handl
|
||||
# configure logging globally
|
||||
import logging.config as logconfig
|
||||
|
||||
from octoprint.logging.filters import TornadoAccessFilter
|
||||
|
||||
logconfig.dictConfig(config)
|
||||
|
||||
# make sure we log any warnings
|
||||
@@ -585,6 +587,9 @@ def set_logging_config(config, debug, verbosity, uncaught_logger, uncaught_handl
|
||||
uncaught_handler = exception_logger
|
||||
sys.excepthook = uncaught_handler
|
||||
|
||||
tornado_logger = log.getLogger("tornado.access")
|
||||
tornado_logger.addFilter(TornadoAccessFilter())
|
||||
|
||||
return logger
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Union
|
||||
|
||||
from past.builtins import basestring, unicode
|
||||
|
||||
from octoprint.logging import filters # noqa: F401
|
||||
from octoprint.logging import handlers # noqa: F401
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
try:
|
||||
from urllib import parse as urlparse
|
||||
except ImportError:
|
||||
import urlparse
|
||||
|
||||
|
||||
class TornadoAccessFilter(logging.Filter):
|
||||
def filter(self, record):
|
||||
try:
|
||||
status, request_line, rtt = record.args
|
||||
|
||||
if status == 409:
|
||||
|
||||
method, url, client = request_line.split()
|
||||
u = urlparse.urlparse(url)
|
||||
if u.path in ("/api/printer",):
|
||||
record.levelno = logging.INFO
|
||||
record.levelname = logging.getLevelName(record.levelno)
|
||||
except Exception:
|
||||
logging.getLogger(__name__).exception(
|
||||
"Error while filtering log record {!r}".format(record)
|
||||
)
|
||||
|
||||
return logging.Filter.filter(self, record)
|
||||
Reference in new issue
Block a user