DAQ: tidied up logging in server.py, added a filter to uvicron access so it does not log successful status access requests, this should be enabled if status debugging is needed, for example if status polling is causing lag.
This commit is contained in:
@@ -7,9 +7,11 @@ import os
|
||||
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
|
||||
|
||||
class QtLogEmitter(QObject):
|
||||
message = Signal(str)
|
||||
|
||||
|
||||
class QtLogHandler(logging.Handler):
|
||||
def __init__(self, emitter: QtLogEmitter):
|
||||
super().__init__()
|
||||
@@ -22,6 +24,56 @@ class QtLogHandler(logging.Handler):
|
||||
except Exception:
|
||||
self.handleError(record)
|
||||
|
||||
class IgnoreSuccessfulStatusAccessFilter(logging.Filter):
|
||||
#Should be disabled if debugging status calls.
|
||||
#In particular if this is causing server/GUI lag
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
message = record.getMessage()
|
||||
return not ('"GET /status HTTP/1.1" 200' in message)
|
||||
|
||||
|
||||
def get_uvicorn_logging_config() -> dict:
|
||||
return {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"filters": {
|
||||
"ignore_successful_status_access": {
|
||||
"()": "aare.common.logger_config.IgnoreSuccessfulStatusAccessFilter",
|
||||
},
|
||||
},
|
||||
"formatters": {
|
||||
"default": {
|
||||
"()": "uvicorn.logging.DefaultFormatter",
|
||||
"fmt": "%(levelprefix)s %(message)s",
|
||||
"use_colors": True,
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"default": {
|
||||
"formatter": "default",
|
||||
"class": "logging.StreamHandler",
|
||||
"stream": "ext://sys.stdout",
|
||||
},
|
||||
"access": {
|
||||
"formatter": "default",
|
||||
"class": "logging.StreamHandler",
|
||||
"stream": "ext://sys.stdout",
|
||||
"filters": ["ignore_successful_status_access"],
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"uvicorn": {
|
||||
"handlers": ["default"],
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
"uvicorn.access": {
|
||||
"handlers": ["access"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def get_config_path(env: str = "dev") -> Path:
|
||||
module_dir = Path(__file__).parent
|
||||
|
||||
@@ -13,9 +13,8 @@ import uvicorn
|
||||
from aare.common.coordinate import AerotechCoordinate
|
||||
from aare.common.auth_models import BatonStatus, BatonRequestStatus
|
||||
from aare.common.coordinate import SmargonCoordinate, Coordinate
|
||||
from aare.common.error_codes import export_error_codes, export_error_codes_grouped
|
||||
from aare.common.logger_config import setup_logger
|
||||
from aare.common.error_codes import export_error_codes_grouped
|
||||
from aare.common.logger_config import setup_logger, get_uvicorn_logging_config
|
||||
from aare.common.models import SampleShortInfo, DAQStatusModel, BeamlineStateEnum, BeamlineSettingsModel, \
|
||||
SampleShortInfoList, SessionStatus, SampleCameraSettings, AutofocusSettings, TokenData, \
|
||||
CryojetSettingsModel, SimpleScanParameters, CrystalSize, FluorescenceSpectrumParameterModel, \
|
||||
|
||||
Reference in New Issue
Block a user