diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 58fd746b6a..379b4f6882 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -204,8 +204,6 @@ def build_custom_checkers(by_lang): 'exclude_line': set([ ('zerver/views/users.py', "return json_error(_(\"Email '%(email)s' not allowed for realm '%(realm)s'\") %"), - ('zproject/settings.py', - "'format': '%(asctime)s %(levelname)-8s %(message)s'"), ('static/templates/settings/bot-settings.handlebars', "'https://hostname.example.com/bots/followup'"), ]), diff --git a/zerver/lib/logging_util.py b/zerver/lib/logging_util.py index 206b816d0a..d97cdea113 100644 --- a/zerver/lib/logging_util.py +++ b/zerver/lib/logging_util.py @@ -125,6 +125,17 @@ def skip_site_packages_logs(record): return False return True +class ZulipFormatter(logging.Formatter): + _fmt = '%(asctime)s %(levelname)-8s %(message)s' + + def __init__(self): + # type: () -> None + super().__init__(fmt=self._fmt) + + def format(self, record): + # type: (logging.LogRecord) -> str + return super().format(record) + def create_logger(name, log_file, log_level, log_format="%(asctime)s %(levelname)-8s %(message)s"): # type: (str, str, str, str) -> Logger """Creates a named logger for use in logging content to a certain diff --git a/zproject/settings.py b/zproject/settings.py index 30c25c32ba..423fc0e0ac 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -1051,7 +1051,7 @@ LOGGING = { 'disable_existing_loggers': False, 'formatters': { 'default': { - 'format': '%(asctime)s %(levelname)-8s %(message)s' + '()': 'zerver.lib.logging_util.ZulipFormatter', } }, 'filters': {