feat(base): Enable user to customize log file location

ref: #744 #436 #752
This commit is contained in:
2025-05-10 21:03:58 +09:30
parent b22baefa5a
commit 24b6bcfa47
4 changed files with 137 additions and 1 deletions

2
.gitignore vendored
View File

@ -20,4 +20,4 @@ package.json
feature_flags.json
coverage_*.json
*-coverage.xml
log/

View File

@ -1,3 +1,22 @@
## Version 1.17.0
- Added setting for log files.
Enables user to specify a default path for centurion's logging. Add the following to your settings file `/etc/itsm/settings.py`
``` py
LOG_FILES = {
"centurion": "/var/log/centurion.log", # Normal Centurion Operations
"weblog": "/var/log/weblog.log", # All web requests made to Centurion
"rest_api": "/var/log/rest_api.log", # Rest API
"catch_all":"/var/log/catch-all.log" # A catch all log. Note: does not log anything that has already been logged.
}
```
With this new setting, the previous setting `LOGGING` will no longer function.
## Version 1.16.0
- Employees model added behind feature flag `2025-00002` and will remain behind this flag until production ready.

View File

@ -80,6 +80,95 @@ FEATURE_FLAG_OVERRIDES = None # Feature Flags to override fetched feature flags
# PROMETHEUS_METRICS_EXPORT_PORT = 8010
# PROMETHEUS_METRICS_EXPORT_ADDRESS = ''
LOG_FILES = { # defaults for devopment. docker includes settings has correct locations
"centurion": "../log/centurion.log",
"weblog": "../log/weblog.log",
"rest_api": "../log/rest_api.log",
"catch_all":"../log/catch-all.log"
}
CENTURION_LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"console": {
"format": "{asctime} {levelname} {message}",
"style": "{",
},
"verbose": {
"format": "{asctime} {levelname} {name} {module} {process:d} {thread:d} {message}",
"style": "{",
},
"simple": {
"format": "{levelname} {message}",
"style": "{",
},
"web_log": {
"format": "{asctime} {levelname} {name} {module} {process:d} {thread:d} {message}",
"style": "{",
},
},
"handlers": {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'console',
},
"file_centurion": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": "centurion.log",
'formatter': 'verbose',
},
"file_weblog": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": "weblog.log",
'formatter': 'web_log',
},
"file_rest_api": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": "rest_api.log",
'formatter': 'verbose',
},
"file_catch_all": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": "catch-all.log",
'formatter': 'verbose',
}
},
"loggers": {
"centurion": {
"handlers": ['console', 'file_centurion'],
"level": "INFO",
"propagate": False,
},
"django.server": {
"handlers": ["file_weblog", 'console'],
"level": "INFO",
"propagate": False,
},
"django": {
"handlers": ['console', 'file_catch_all'],
"level": "INFO",
"propagate": False,
},
'rest_framework': {
'handlers': ['file_rest_api', 'console'],
'level': 'INFO',
'propagate': False,
},
'': {
'handlers': ['file_catch_all'],
'level': 'INFO',
'propagate': True,
},
},
}
METRICS_ENABLED = False # Enable Metrics
METRICS_EXPORT_PORT = 8080 # Port to serve metrics on
METRICS_MULTIPROC_DIR = '/tmp/prometheus' # path the metrics from multiple-process' save to
@ -393,7 +482,22 @@ CSRF_TRUSTED_ORIGINS = [
*TRUSTED_ORIGINS
]
# Add the user specified log files
CENTURION_LOGGING['handlers']['file_centurion']['filename'] = LOG_FILES['centurion']
CENTURION_LOGGING['handlers']['file_weblog']['filename'] = LOG_FILES['weblog']
CENTURION_LOGGING['handlers']['file_rest_api']['filename'] = LOG_FILES['rest_api']
CENTURION_LOGGING['handlers']['file_catch_all']['filename'] = LOG_FILES['catch_all']
if str(CENTURION_LOGGING['handlers']['file_centurion']['filename']).startswith('../log'):
if not os.path.exists('../log'): # Create log dir
os.makedirs('../log')
if DEBUG:
INSTALLED_APPS += [
'debug_toolbar',
]
@ -407,6 +511,10 @@ if DEBUG:
]
# Setup Logging
LOGGING = CENTURION_LOGGING
if METRICS_ENABLED:
INSTALLED_APPS += [ 'django_prometheus', ]

View File

@ -33,6 +33,15 @@ FEATURE_FLAGGING_ENABLED = True # Turn Feature Flagging on/off
FEATURE_FLAG_OVERRIDES = [] # Feature Flag Overrides. Takes preceedence over downloaded feature flags.
LOG_FILES = { # Location where log files will be created
"centurion": "/var/log/centurion.log",
"weblog": "/var/log/weblog.log",
"rest_api": "/var/log/rest_api.log",
"catch_all":"/var/log/catch-all.log"
}
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True