Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
computed_settings: Provide a helper for configuring a new log file.
Alex Vandiver636afa01024f
diff --git a/zproject/computed_settings.py b/zproject/computed_settings.pyindex 90c7b547677..e852bdf23b9 100644--- a/zproject/computed_settings.py+++ b/zproject/computed_settings.py@@ -3,7 +3,7 @@ import osimport sysimport timefrom copy import deepcopy-from typing import Any, Dict, Final, List, Tuple, Union+from typing import Any, Dict, Final, List, Literal, Tuple, Unionfrom urllib.parse import urljoinfrom scripts.lib.zulip_tools import get_tornado_ports@@ -714,6 +714,19 @@ def skip_site_packages_logs(record: logging.LogRecord) -> bool:return "site-packages" not in record.pathname+def file_handler(+ filename: str,+ level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "DEBUG",+ formatter: str = "default",+) -> Dict[str, str]:+ return {+ "filename": filename,+ "level": level,+ "formatter": formatter,+ "class": "logging.handlers.WatchedFileHandler",+ }++LOGGING: Dict[str, Any] = {"version": 1,"disable_existing_loggers": False,@@ -754,6 +767,11 @@ LOGGING: Dict[str, Any] = {},},"handlers": {+ "console": {+ "level": "DEBUG",+ "class": "logging.StreamHandler",+ "formatter": "default",+ },"mail_admins": {"level": "ERROR","class": "django.utils.log.AdminEmailHandler",@@ -763,71 +781,20 @@ LOGGING: Dict[str, Any] = {else []),},- "analytics_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": ANALYTICS_LOG_PATH,- },- "auth_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": AUTH_LOG_PATH,- },- "console": {- "level": "DEBUG",- "class": "logging.StreamHandler",- "formatter": "default",- },- "file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": FILE_LOG_PATH,- },- "errors_file": {- "level": "WARNING",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": ERROR_FILE_LOG_PATH,- },- "ldap_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": LDAP_LOG_PATH,- },- "scim_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": SCIM_LOG_PATH,- },- "slow_queries_file": {- "level": "INFO",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "default",- "filename": SLOW_QUERIES_LOG_PATH,- },- "webhook_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "webhook_request_data",- "filename": WEBHOOK_LOG_PATH,- },- "webhook_unsupported_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "webhook_request_data",- "filename": WEBHOOK_UNSUPPORTED_EVENTS_LOG_PATH,- },- "webhook_anomalous_file": {- "level": "DEBUG",- "class": "logging.handlers.WatchedFileHandler",- "formatter": "webhook_request_data",- "filename": WEBHOOK_ANOMALOUS_PAYLOADS_LOG_PATH,- },+ "analytics_file": file_handler(ANALYTICS_LOG_PATH),+ "auth_file": file_handler(AUTH_LOG_PATH),+ "errors_file": file_handler(ERROR_FILE_LOG_PATH, level="WARNING"),+ "file": file_handler(FILE_LOG_PATH),+ "ldap_file": file_handler(LDAP_LOG_PATH),+ "scim_file": file_handler(SCIM_LOG_PATH),+ "slow_queries_file": file_handler(SLOW_QUERIES_LOG_PATH, level="INFO"),+ "webhook_anomalous_file": file_handler(+ WEBHOOK_ANOMALOUS_PAYLOADS_LOG_PATH, formatter="webhook_request_data"+ ),+ "webhook_file": file_handler(WEBHOOK_LOG_PATH, formatter="webhook_request_data"),+ "webhook_unsupported_file": file_handler(+ WEBHOOK_UNSUPPORTED_EVENTS_LOG_PATH, formatter="webhook_request_data"+ ),},"loggers": {# The Python logging module uses a hierarchy of logger names for config: