diff --git a/api/app.py b/api/app.py index 6227c73ea3..52461aac93 100644 --- a/api/app.py +++ b/api/app.py @@ -110,9 +110,21 @@ def create_app() -> Flask: level=app.config.get('LOG_LEVEL'), format=app.config.get('LOG_FORMAT'), datefmt=app.config.get('LOG_DATEFORMAT'), - handlers=log_handlers + handlers=log_handlers, + force=True ) + log_tz = app.config.get('LOG_TZ') + if log_tz: + from datetime import datetime + import pytz + timezone = pytz.timezone(log_tz) + + def time_converter(seconds): + return datetime.utcfromtimestamp(seconds).astimezone(timezone).timetuple() + + for handler in logging.root.handlers: + handler.formatter.converter = time_converter initialize_extensions(app) register_blueprints(app) register_commands(app) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index f880ab6f50..e820761b06 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -165,6 +165,11 @@ class LoggingConfigs(BaseModel): default=None, ) + LOG_TZ: Optional[str] = Field( + description='specify log timezone, eg: America/New_York', + default=None, + ) + class ModelLoadBalanceConfigs(BaseModel): """