Commit 850f8a36 by Calen Pennington

Clean up logging to have sensible defaults for production.

parent 6a43b910
from os import environ from os import environ
import platform
import sys
import yaml import yaml
from logging.handlers import SysLogHandler
from course_discovery.settings.base import * from course_discovery.settings.base import *
from course_discovery.settings.utils import get_env_setting from course_discovery.settings.utils import get_env_setting
...@@ -10,7 +13,25 @@ TEMPLATE_DEBUG = DEBUG ...@@ -10,7 +13,25 @@ TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
LOGGING = environ.get('LOGGING', LOGGING) LOGGING['handlers']['local'] = {
'level': 'INFO',
'class': 'logging.handlers.SysLogHandler',
# Use a different address for Mac OS X
'address': '/var/run/syslog' if sys.platform == "darwin" else '/dev/log',
'formatter': 'syslog_format',
'facility': SysLogHandler.LOG_LOCAL0,
}
LOGGING['formatters']['syslog_format'] = {
format: (
"[service_variant=course_discovery]"
"[%(name)s][env:no_env] %(levelname)s "
"[{hostname} %(process)d] [%(filename)s:%(lineno)d] "
"- %(message)s"
).format(
hostname=platform.node().split(".")[0]
)
}
CONFIG_FILE = get_env_setting('COURSE_DISCOVERY_CFG') CONFIG_FILE = get_env_setting('COURSE_DISCOVERY_CFG')
with open(CONFIG_FILE) as f: with open(CONFIG_FILE) as f:
......
...@@ -10,6 +10,6 @@ def get_env_setting(setting): ...@@ -10,6 +10,6 @@ def get_env_setting(setting):
try: try:
return environ[setting] return environ[setting]
except KeyError: except KeyError:
error_msg = "Set the [%s] env variable!" % setting error_msg = "Set the [{}] env variable!".format(setting)
raise ImproperlyConfigured(error_msg) raise ImproperlyConfigured(error_msg)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment