初步实现多project pipeline
This commit is contained in:
@@ -8,6 +8,14 @@ from typing import Optional
|
||||
APP_LOGGER_NAME = "sync_state_machine"
|
||||
|
||||
|
||||
class ScopeLoggerAdapter(logging.LoggerAdapter):
|
||||
def process(self, msg, kwargs):
|
||||
scope = self.extra.get("scope")
|
||||
if scope and not str(msg).startswith("["):
|
||||
msg = f"[{scope}] {msg}"
|
||||
return msg, kwargs
|
||||
|
||||
|
||||
class _NodeLogFilter(logging.Filter):
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
message = record.getMessage()
|
||||
@@ -30,6 +38,10 @@ def get_logger(name: Optional[str] = None) -> logging.Logger:
|
||||
return logging.getLogger(f"{APP_LOGGER_NAME}.{name}")
|
||||
|
||||
|
||||
def get_scope_logger(scope: str, name: Optional[str] = None) -> logging.LoggerAdapter:
|
||||
return ScopeLoggerAdapter(get_logger(name), {"scope": scope})
|
||||
|
||||
|
||||
def clear_app_logger_handlers(logger: Optional[logging.Logger] = None) -> None:
|
||||
target = logger or get_app_logger()
|
||||
handlers = list(target.handlers)
|
||||
|
||||
Reference in New Issue
Block a user