From 0e2322a3222bb6bebf9d6316f39780d19c913771 Mon Sep 17 00:00:00 2001 From: Abhilash Verma Date: Sun, 12 Aug 2018 05:26:58 +0530 Subject: [PATCH] logging: Show timestamp in UTC in non-django production scripts. Done in pair programming with @aero31aero. Fixes #9678. --- puppet/zulip/files/postgresql/pg_backup_and_purge | 2 ++ puppet/zulip/files/postgresql/process_fts_updates | 1 + scripts/lib/upgrade-zulip | 2 ++ scripts/lib/upgrade-zulip-stage-2 | 2 ++ scripts/restart-server | 1 + scripts/upgrade-zulip-from-git | 2 ++ zerver/lib/notifications.py | 2 ++ 7 files changed, 12 insertions(+) diff --git a/puppet/zulip/files/postgresql/pg_backup_and_purge b/puppet/zulip/files/postgresql/pg_backup_and_purge index cc3aba0198..21252cf729 100755 --- a/puppet/zulip/files/postgresql/pg_backup_and_purge +++ b/puppet/zulip/files/postgresql/pg_backup_and_purge @@ -8,10 +8,12 @@ import sys import logging import dateutil.parser import pytz +import time from datetime import datetime, timedelta if False: from typing import Dict, List +logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s") logger = logging.getLogger(__name__) diff --git a/puppet/zulip/files/postgresql/process_fts_updates b/puppet/zulip/files/postgresql/process_fts_updates index 66b6e640da..de0ae3f9b8 100755 --- a/puppet/zulip/files/postgresql/process_fts_updates +++ b/puppet/zulip/files/postgresql/process_fts_updates @@ -52,6 +52,7 @@ def am_master(cursor): cursor.execute("SELECT pg_is_in_recovery()") return not cursor.fetchall()[0][0] +logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s") logger = logging.getLogger("process_fts_updates") logger.setLevel(logging.DEBUG) diff --git a/scripts/lib/upgrade-zulip b/scripts/lib/upgrade-zulip index 0b93af874a..c369eaaa3c 100755 --- a/scripts/lib/upgrade-zulip +++ b/scripts/lib/upgrade-zulip @@ -4,6 +4,7 @@ import shutil import sys import subprocess import logging +import time TARBALL_ARCHIVE_PATH = "/home/zulip/archives" os.environ["PYTHONUNBUFFERED"] = "y" @@ -12,6 +13,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, \ su_to_zulip, get_deployment_lock, release_deployment_lock +logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s upgrade-zulip: %(message)s", level=logging.INFO) diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index 5feef85632..9b16acc442 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -9,6 +9,7 @@ import subprocess import os import sys import logging +import time os.environ["PYTHONUNBUFFERED"] = "y" @@ -20,6 +21,7 @@ os.environ["LANGUAGE"] = "en_US.UTF-8" sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, su_to_zulip +logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s upgrade-zulip-stage-2: %(message)s", level=logging.INFO) diff --git a/scripts/restart-server b/scripts/restart-server index b0c5274eb6..46c9654bba 100755 --- a/scripts/restart-server +++ b/scripts/restart-server @@ -9,6 +9,7 @@ import time sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from scripts.lib.zulip_tools import ENDC, OKGREEN, DEPLOYMENTS_DIR +logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s restart-server: %(message)s", level=logging.INFO) diff --git a/scripts/upgrade-zulip-from-git b/scripts/upgrade-zulip-from-git index 0b6258419f..838172e964 100755 --- a/scripts/upgrade-zulip-from-git +++ b/scripts/upgrade-zulip-from-git @@ -4,6 +4,7 @@ import configparser import sys import subprocess import logging +import time config_file = configparser.RawConfigParser() config_file.read("/etc/zulip/zulip.conf") @@ -24,6 +25,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \ get_deployment_lock, release_deployment_lock, su_to_zulip +logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s upgrade-zulip-from-git: %(message)s", level=logging.INFO) diff --git a/zerver/lib/notifications.py b/zerver/lib/notifications.py index 646484b38e..3d6c26d91c 100644 --- a/zerver/lib/notifications.py +++ b/zerver/lib/notifications.py @@ -465,6 +465,8 @@ def clear_scheduled_emails(user_id: int, email_type: Optional[int]=None) -> None def log_digest_event(msg: str) -> None: import logging + import time + logging.Formatter.converter = time.gmtime logging.basicConfig(filename=settings.DIGEST_LOG_PATH, level=logging.INFO) logging.info(msg)