logging: Show timestamp in UTC in non-django production scripts.

Done in pair programming with @aero31aero.

Fixes #9678.
This commit is contained in:
Abhilash Verma 2018-08-12 05:26:58 +05:30 committed by Tim Abbott
parent 920ef2b7f7
commit 0e2322a322
7 changed files with 12 additions and 0 deletions

View File

@ -8,10 +8,12 @@ import sys
import logging import logging
import dateutil.parser import dateutil.parser
import pytz import pytz
import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
if False: if False:
from typing import Dict, List from typing import Dict, List
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s") logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -52,6 +52,7 @@ def am_master(cursor):
cursor.execute("SELECT pg_is_in_recovery()") cursor.execute("SELECT pg_is_in_recovery()")
return not cursor.fetchall()[0][0] return not cursor.fetchall()[0][0]
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s") logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
logger = logging.getLogger("process_fts_updates") logger = logging.getLogger("process_fts_updates")
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)

View File

@ -4,6 +4,7 @@ import shutil
import sys import sys
import subprocess import subprocess
import logging import logging
import time
TARBALL_ARCHIVE_PATH = "/home/zulip/archives" TARBALL_ARCHIVE_PATH = "/home/zulip/archives"
os.environ["PYTHONUNBUFFERED"] = "y" 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, \ from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, \
su_to_zulip, get_deployment_lock, release_deployment_lock su_to_zulip, get_deployment_lock, release_deployment_lock
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s upgrade-zulip: %(message)s", logging.basicConfig(format="%(asctime)s upgrade-zulip: %(message)s",
level=logging.INFO) level=logging.INFO)

View File

@ -9,6 +9,7 @@ import subprocess
import os import os
import sys import sys
import logging import logging
import time
os.environ["PYTHONUNBUFFERED"] = "y" 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__), '..', '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, su_to_zulip 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", logging.basicConfig(format="%(asctime)s upgrade-zulip-stage-2: %(message)s",
level=logging.INFO) level=logging.INFO)

View File

@ -9,6 +9,7 @@ import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from scripts.lib.zulip_tools import ENDC, OKGREEN, DEPLOYMENTS_DIR from scripts.lib.zulip_tools import ENDC, OKGREEN, DEPLOYMENTS_DIR
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s restart-server: %(message)s", logging.basicConfig(format="%(asctime)s restart-server: %(message)s",
level=logging.INFO) level=logging.INFO)

View File

@ -4,6 +4,7 @@ import configparser
import sys import sys
import subprocess import subprocess
import logging import logging
import time
config_file = configparser.RawConfigParser() config_file = configparser.RawConfigParser()
config_file.read("/etc/zulip/zulip.conf") 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, \ from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
get_deployment_lock, release_deployment_lock, su_to_zulip 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", logging.basicConfig(format="%(asctime)s upgrade-zulip-from-git: %(message)s",
level=logging.INFO) level=logging.INFO)

View File

@ -465,6 +465,8 @@ def clear_scheduled_emails(user_id: int, email_type: Optional[int]=None) -> None
def log_digest_event(msg: str) -> None: def log_digest_event(msg: str) -> None:
import logging import logging
import time
logging.Formatter.converter = time.gmtime
logging.basicConfig(filename=settings.DIGEST_LOG_PATH, level=logging.INFO) logging.basicConfig(filename=settings.DIGEST_LOG_PATH, level=logging.INFO)
logging.info(msg) logging.info(msg)