From d4a7a4ab5a4c7fb57df1d011928211da9c19d33b Mon Sep 17 00:00:00 2001 From: jbromwic <65613282+jbromwic@users.noreply.github.com> Date: Tue, 19 May 2020 16:57:19 +0100 Subject: [PATCH] Update configuration.py to use LOGGING environment variable Update configuration.py to use a LOGGING environment variable to allow LOGGING configuration to be set via docker-compose. LOGGING environment variable should be set to the full dictionary - example below: `LOGGING: "{'version': 1, 'disable_existing_loggers': False, 'formatters': { 'timestamp': { 'format': '{asctime} {levelname} {message}', 'style': '{', }, }, 'handlers': { 'netbox-auth': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'formatter': 'timestamp', 'filename': '/var/log/netbox/netbox-auth.log', }, 'netbox': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'formatter': 'timestamp', 'filename': '/var/log/netbox/netbox.log', }, }, 'loggers': { 'netbox.auth': { 'handlers': ['netbox-auth'], 'level': 'DEBUG', }, 'django_auth_ldap': { 'handlers': ['netbox-auth'], 'level': 'DEBUG', }, 'netbox.views': { 'handlers': ['netbox'], 'level': 'DEBUG', }, 'netbox.api.views': { 'handlers': ['netbox'], 'level': 'DEBUG', }, },}"` --- configuration/configuration.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configuration/configuration.py b/configuration/configuration.py index 84bb6ae1d..ba32e0d97 100644 --- a/configuration/configuration.py +++ b/configuration/configuration.py @@ -1,6 +1,7 @@ import os import re import socket +import ast # For reference see http://netbox.readthedocs.io/en/latest/configuration/mandatory-settings/ # Based on https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration.example.py @@ -144,7 +145,10 @@ def read_secret(secret_name): # Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs: # https://docs.djangoproject.com/en/1.11/topics/logging/ -LOGGING = {} +if "LOGGING" in os.environ: + LOGGING = ast.literal_eval(os.environ.get('LOGGING')) +else: + LOGGING = {} # Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users # are permitted to access most data in NetBox (excluding secrets) but not make any changes.