diff --git a/bin/log-management-command b/bin/log-management-command new file mode 100755 index 0000000000..e4c7dd061c --- /dev/null +++ b/bin/log-management-command @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import sys +import logging +import os +sys.path.append(os.path.join(os.path.dirname(__file__), "..")) +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings") +from django.conf import settings + +logger = logging.getLogger("zulip.management") +file_handler = logging.FileHandler(settings.MANAGEMENT_LOG_PATH) +formatter = logging.Formatter("%(asctime)s: %(message)s") +file_handler.setFormatter(formatter) +logger.addHandler(file_handler) +logger.setLevel(logging.INFO) + +logger.info("Ran '%s'" % (sys.argv[1],)) diff --git a/manage.py b/manage.py index e609bf2513..afb02d13a7 100755 --- a/manage.py +++ b/manage.py @@ -1,14 +1,21 @@ #!/usr/bin/env python import os import sys +import logging +import subprocess if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings") + + from django.conf import settings + + logger = logging.getLogger("zulip.management") + subprocess.check_call([os.path.join(os.path.dirname(__file__), "bin", "log-management-command"), + " ".join(sys.argv)]) if "--no-traceback" not in sys.argv and len(sys.argv) > 1: sys.argv.append("--traceback") - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings") - from django.core.management import execute_from_command_line execute_from_command_line(sys.argv) diff --git a/zproject/settings.py b/zproject/settings.py index e587c272ce..33b56d29f7 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -587,6 +587,7 @@ CACHES = { if DEPLOYED: SERVER_LOG_PATH = "/var/log/zulip/server.log" + MANAGEMENT_LOG_PATH = "/var/log/zulip/manage.log" WORKER_LOG_PATH = "/var/log/zulip/workers.log" if ENTERPRISE: EVENT_LOG_DIR = None @@ -601,6 +602,7 @@ if DEPLOYED: else: EVENT_LOG_DIR = 'event_log' SERVER_LOG_PATH = "server.log" + MANAGEMENT_LOG_PATH = "manage.log" WORKER_LOG_PATH = "workers.log" STATS_DIR = 'stats' PERSISTENT_QUEUE_FILENAME = "event_queues.pickle" @@ -683,6 +685,11 @@ LOGGING = { 'level': 'INFO', 'propagate': False, }, + 'zulip.management': { + 'handlers': ['file'], + 'level': 'INFO', + 'propagate': False, + }, ## Uncomment the following to get all database queries logged to the console # 'django.db': { # 'handlers': ['console'], diff --git a/zproject/test_settings.py b/zproject/test_settings.py index a355921788..62a3577b36 100644 --- a/zproject/test_settings.py +++ b/zproject/test_settings.py @@ -48,3 +48,4 @@ CACHES['database'] = { } LOGGING['loggers']['zulip.requests']['level'] = 'CRITICAL' +LOGGING['loggers']['zulip.management']['level'] = 'CRITICAL'