Commit 09ebb0f3 by Clinton Blackburn

Updated logging configuration (#117)

ECOM-4540
parent 57af64c4
import os import os
import platform
from logging.handlers import SysLogHandler
from os.path import join, abspath, dirname from os.path import join, abspath, dirname
from sys import path from sys import path
# PATH vars
from urllib.parse import urljoin
here = lambda *x: join(abspath(dirname(__file__)), *x) here = lambda *x: join(abspath(dirname(__file__)), *x)
PROJECT_ROOT = here("..") PROJECT_ROOT = here("..")
...@@ -199,56 +199,71 @@ PLATFORM_NAME = 'Your Platform Name Here' ...@@ -199,56 +199,71 @@ PLATFORM_NAME = 'Your Platform Name Here'
# END OPENEDX-SPECIFIC CONFIGURATION # END OPENEDX-SPECIFIC CONFIGURATION
# Set up logging for development use (logging to stdout) # Set up logging for development use (logging to stdout)
level = 'DEBUG' if DEBUG else 'INFO'
hostname = platform.node().split(".")[0]
syslog_address = '/var/run/syslog' if platform.system().lower() == 'darwin' else '/dev/log'
syslog_format = '[service_variant=discovery][%(name)s] %(levelname)s [{hostname} %(process)d] ' \
'[%(pathname)s:%(lineno)d] - %(message)s'.format(hostname=hostname)
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
'formatters': { 'formatters': {
'standard': { 'standard': {
'format': '%(asctime)s %(levelname)s %(process)d ' 'format': '%(asctime)s %(levelname)s %(process)d [%(name)s] %(pathname)s:%(lineno)d - %(message)s',
'[%(name)s] %(filename)s:%(lineno)d - %(message)s',
}, },
'syslog_format': {'format': syslog_format},
}, },
'handlers': { 'handlers': {
'console': { 'console': {
'level': 'DEBUG', 'level': level,
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter': 'standard', 'formatter': 'standard',
'stream': 'ext://sys.stdout', 'stream': 'ext://sys.stdout',
}, },
'local': {
'level': level,
'class': 'logging.handlers.SysLogHandler',
# Use a different address for Mac OS X
'address': syslog_address,
'formatter': 'syslog_format',
'facility': SysLogHandler.LOG_LOCAL0,
},
}, },
'loggers': { 'loggers': {
'django': { 'django': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'propagate': True, 'propagate': True,
'level': 'INFO' 'level': 'INFO'
}, },
'requests': { 'requests': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'propagate': True, 'propagate': True,
'level': 'WARNING' 'level': 'WARNING'
}, },
'factory': { 'factory': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'propagate': True, 'propagate': True,
'level': 'WARNING' 'level': 'WARNING'
}, },
'elasticsearch': { 'elasticsearch': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'propagate': True, 'propagate': True,
'level': 'WARNING' 'level': 'WARNING'
}, },
'urllib3': { 'urllib3': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'propagate': True, 'propagate': True,
'level': 'WARNING' 'level': 'WARNING'
}, },
'django.request': { 'django.request': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'propagate': True, 'propagate': True,
'level': 'WARNING' 'level': 'WARNING'
}, },
'': { '': {
'handlers': ['console'], 'handlers': ['console', 'local'],
'level': 'DEBUG', 'level': 'DEBUG',
'propagate': False 'propagate': False
}, },
......
...@@ -2,7 +2,10 @@ from course_discovery.settings.production import * ...@@ -2,7 +2,10 @@ from course_discovery.settings.production import *
DEBUG = True DEBUG = True
del LOGGING['handlers']['local'] # Docker does not support the syslog socket at /dev/log. Rely on the console.
LOGGING['handlers']['local'] = {
'class': 'logging.NullHandler',
}
# TOOLBAR CONFIGURATION # TOOLBAR CONFIGURATION
# See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html # See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html
......
import platform
import sys
import warnings import warnings
from logging.handlers import SysLogHandler
from os import environ from os import environ
import certifi import certifi
...@@ -16,25 +13,7 @@ TEMPLATE_DEBUG = DEBUG ...@@ -16,25 +13,7 @@ TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
LOGGING['handlers']['local'] = { LOGGING['handlers']['local']['level'] = 'INFO'
'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]
)
}
# Keep track of the names of settings that represent dicts. Instead of overriding the values in base.py, # Keep track of the names of settings that represent dicts. Instead of overriding the values in base.py,
# the values read from disk should UPDATE the pre-configured dicts. # the values read from disk should UPDATE the pre-configured dicts.
......
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