mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-07 18:30:54 +00:00
implement trace option
This commit is contained in:
parent
02471b6c90
commit
ef1c2b835f
3 changed files with 47 additions and 3 deletions
|
@ -52,7 +52,10 @@ def _get_application_instance(config_path: str, wsgi_errors: types.ErrorStream
|
|||
configuration = config.load(config.parse_compound_paths(
|
||||
config.DEFAULT_CONFIG_PATH,
|
||||
config_path))
|
||||
log.set_level(cast(str, configuration.get("logging", "level")), configuration.get("logging", "backtrace_on_debug"))
|
||||
log.set_level(cast(str, configuration.get("logging", "level")),
|
||||
configuration.get("logging", "backtrace_on_debug"),
|
||||
configuration.get("logging", "trace_on_debug"),
|
||||
configuration.get("logging", "trace_filter"))
|
||||
# Log configuration after logger is configured
|
||||
default_config_active = True
|
||||
for source, miss in configuration.sources():
|
||||
|
|
|
@ -165,7 +165,10 @@ def run() -> None:
|
|||
sys.exit(1)
|
||||
|
||||
# Configure logging
|
||||
log.set_level(cast(str, configuration.get("logging", "level")), configuration.get("logging", "backtrace_on_debug"))
|
||||
log.set_level(cast(str, configuration.get("logging", "level")),
|
||||
configuration.get("logging", "backtrace_on_debug"),
|
||||
configuration.get("logging", "trace_on_debug"),
|
||||
configuration.get("logging", "trace_filter"))
|
||||
|
||||
# Log configuration after logger is configured
|
||||
default_config_active = True
|
||||
|
|
|
@ -57,8 +57,35 @@ class RemoveTracebackFilter(logging.Filter):
|
|||
return True
|
||||
|
||||
|
||||
class RemoveTRACEFilter(logging.Filter):
|
||||
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
if record.msg.startswith("TRACE"):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class PassTRACETOKENFilter(logging.Filter):
|
||||
def __init__(self, trace_filter: str):
|
||||
super().__init__()
|
||||
self.trace_filter = trace_filter
|
||||
self.prefix = "TRACE/" + self.trace_filter
|
||||
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
if record.msg.startswith("TRACE"):
|
||||
if record.msg.startswith(self.prefix):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
REMOVE_TRACEBACK_FILTER: logging.Filter = RemoveTracebackFilter()
|
||||
|
||||
REMOVE_TRACE_FILTER: logging.Filter = RemoveTRACEFilter()
|
||||
|
||||
|
||||
class IdentLogRecordFactory:
|
||||
"""LogRecordFactory that adds ``ident`` attribute."""
|
||||
|
@ -231,7 +258,7 @@ logger_display_backtrace_disabled: bool = False
|
|||
logger_display_backtrace_enabled: bool = False
|
||||
|
||||
|
||||
def set_level(level: Union[int, str], backtrace_on_debug: bool) -> None:
|
||||
def set_level(level: Union[int, str], backtrace_on_debug: bool, trace_on_debug: bool = False, trace_filter: str = "") -> None:
|
||||
"""Set logging level for global logger."""
|
||||
global logger_display_backtrace_disabled
|
||||
global logger_display_backtrace_enabled
|
||||
|
@ -255,3 +282,14 @@ def set_level(level: Union[int, str], backtrace_on_debug: bool) -> None:
|
|||
logger.debug("Logging of backtrace is enabled by option in this loglevel")
|
||||
logger_display_backtrace_enabled = True
|
||||
logger.removeFilter(REMOVE_TRACEBACK_FILTER)
|
||||
if trace_on_debug:
|
||||
if trace_filter != "":
|
||||
logger.debug("Logging messages starting with 'TRACE/%s' enabled", trace_filter)
|
||||
logger.addFilter(PassTRACETOKENFilter(trace_filter))
|
||||
logger.removeFilter(REMOVE_TRACE_FILTER)
|
||||
else:
|
||||
logger.debug("Logging messages starting with 'TRACE' enabled")
|
||||
logger.removeFilter(REMOVE_TRACE_FILTER)
|
||||
else:
|
||||
logger.debug("Logging messages starting with 'TRACE' disabled")
|
||||
logger.addFilter(REMOVE_TRACE_FILTER)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue