mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 03:26:45 +00:00
feat: Add setting for controling console logs (#8903)
* Add setting for controling console logs * respect console_log setting * use var for defualt handler
This commit is contained in:
parent
89dfa0f6f9
commit
3d2f800c73
3
.github/workflows/qc_checks.yaml
vendored
3
.github/workflows/qc_checks.yaml
vendored
@ -285,6 +285,7 @@ jobs:
|
|||||||
INVENTREE_DB_NAME: ./inventree.sqlite
|
INVENTREE_DB_NAME: ./inventree.sqlite
|
||||||
INVENTREE_DB_ENGINE: sqlite3
|
INVENTREE_DB_ENGINE: sqlite3
|
||||||
INVENTREE_PLUGINS_ENABLED: true
|
INVENTREE_PLUGINS_ENABLED: true
|
||||||
|
INVENTREE_CONSOLE_LOG: false
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
python_version: ${{ matrix.python_version }}
|
python_version: ${{ matrix.python_version }}
|
||||||
|
|
||||||
@ -328,6 +329,7 @@ jobs:
|
|||||||
INVENTREE_DB_PORT: 5432
|
INVENTREE_DB_PORT: 5432
|
||||||
INVENTREE_DEBUG: true
|
INVENTREE_DEBUG: true
|
||||||
INVENTREE_LOG_LEVEL: INFO
|
INVENTREE_LOG_LEVEL: INFO
|
||||||
|
INVENTREE_CONSOLE_LOG: false
|
||||||
INVENTREE_CACHE_HOST: localhost
|
INVENTREE_CACHE_HOST: localhost
|
||||||
INVENTREE_PLUGINS_ENABLED: true
|
INVENTREE_PLUGINS_ENABLED: true
|
||||||
|
|
||||||
@ -377,6 +379,7 @@ jobs:
|
|||||||
INVENTREE_DB_PORT: 3306
|
INVENTREE_DB_PORT: 3306
|
||||||
INVENTREE_DEBUG: true
|
INVENTREE_DEBUG: true
|
||||||
INVENTREE_LOG_LEVEL: INFO
|
INVENTREE_LOG_LEVEL: INFO
|
||||||
|
INVENTREE_CONSOLE_LOG: false
|
||||||
INVENTREE_PLUGINS_ENABLED: true
|
INVENTREE_PLUGINS_ENABLED: true
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
@ -97,6 +97,7 @@ The following debugging / logging options are available:
|
|||||||
| INVENTREE_LOG_LEVEL | log_level | Set level of logging to terminal | WARNING |
|
| INVENTREE_LOG_LEVEL | log_level | Set level of logging to terminal | WARNING |
|
||||||
| INVENTREE_JSON_LOG | json_log | log as json | False |
|
| INVENTREE_JSON_LOG | json_log | log as json | False |
|
||||||
| INVENTREE_WRITE_LOG | write_log | Enable writing of log messages to file at config base | False |
|
| INVENTREE_WRITE_LOG | write_log | Enable writing of log messages to file at config base | False |
|
||||||
|
| INVENTREE_CONSOLE_LOG | console_log | Enable logging to console | True |
|
||||||
|
|
||||||
### Debug Mode
|
### Debug Mode
|
||||||
|
|
||||||
|
@ -83,11 +83,13 @@ DEBUG = get_boolean_setting('INVENTREE_DEBUG', 'debug', False)
|
|||||||
LOG_LEVEL = get_setting('INVENTREE_LOG_LEVEL', 'log_level', 'WARNING')
|
LOG_LEVEL = get_setting('INVENTREE_LOG_LEVEL', 'log_level', 'WARNING')
|
||||||
JSON_LOG = get_boolean_setting('INVENTREE_JSON_LOG', 'json_log', False)
|
JSON_LOG = get_boolean_setting('INVENTREE_JSON_LOG', 'json_log', False)
|
||||||
WRITE_LOG = get_boolean_setting('INVENTREE_WRITE_LOG', 'write_log', False)
|
WRITE_LOG = get_boolean_setting('INVENTREE_WRITE_LOG', 'write_log', False)
|
||||||
|
CONSOLE_LOG = get_boolean_setting('INVENTREE_CONSOLE_LOG', 'console_log', True)
|
||||||
|
|
||||||
logging.basicConfig(level=LOG_LEVEL, format='%(asctime)s %(levelname)s %(message)s')
|
logging.basicConfig(level=LOG_LEVEL, format='%(asctime)s %(levelname)s %(message)s')
|
||||||
|
|
||||||
if LOG_LEVEL not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
|
if LOG_LEVEL not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
|
||||||
LOG_LEVEL = 'WARNING' # pragma: no cover
|
LOG_LEVEL = 'WARNING' # pragma: no cover
|
||||||
|
DEFAULT_LOG_HANDLER = ['console'] if CONSOLE_LOG else []
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': False,
|
'disable_existing_loggers': False,
|
||||||
@ -114,10 +116,12 @@ LOGGING = {
|
|||||||
},
|
},
|
||||||
'handlers': {
|
'handlers': {
|
||||||
'console': {'class': 'logging.StreamHandler', 'formatter': 'plain_console'}
|
'console': {'class': 'logging.StreamHandler', 'formatter': 'plain_console'}
|
||||||
},
|
}
|
||||||
|
if CONSOLE_LOG
|
||||||
|
else {},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'django_structlog': {'handlers': ['console'], 'level': LOG_LEVEL},
|
'django_structlog': {'handlers': DEFAULT_LOG_HANDLER, 'level': LOG_LEVEL},
|
||||||
'inventree': {'handlers': ['console'], 'level': LOG_LEVEL},
|
'inventree': {'handlers': DEFAULT_LOG_HANDLER, 'level': LOG_LEVEL},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,14 +133,14 @@ if WRITE_LOG and JSON_LOG: # pragma: no cover
|
|||||||
'filename': str(BASE_DIR.joinpath('logs.json')),
|
'filename': str(BASE_DIR.joinpath('logs.json')),
|
||||||
'formatter': 'json_formatter',
|
'formatter': 'json_formatter',
|
||||||
}
|
}
|
||||||
LOGGING['loggers']['django_structlog']['handlers'] += ['log_file']
|
DEFAULT_LOG_HANDLER.append('log_file')
|
||||||
elif WRITE_LOG: # pragma: no cover
|
elif WRITE_LOG: # pragma: no cover
|
||||||
LOGGING['handlers']['log_file'] = {
|
LOGGING['handlers']['log_file'] = {
|
||||||
'class': 'logging.handlers.WatchedFileHandler',
|
'class': 'logging.handlers.WatchedFileHandler',
|
||||||
'filename': str(BASE_DIR.joinpath('logs.log')),
|
'filename': str(BASE_DIR.joinpath('logs.log')),
|
||||||
'formatter': 'key_value',
|
'formatter': 'key_value',
|
||||||
}
|
}
|
||||||
LOGGING['loggers']['django_structlog']['handlers'] += ['log_file']
|
DEFAULT_LOG_HANDLER.append('log_file')
|
||||||
|
|
||||||
structlog.configure(
|
structlog.configure(
|
||||||
processors=[
|
processors=[
|
||||||
@ -377,7 +381,7 @@ if LDAP_AUTH:
|
|||||||
LOGGING['loggers'] = {}
|
LOGGING['loggers'] = {}
|
||||||
LOGGING['loggers']['django_auth_ldap'] = {
|
LOGGING['loggers']['django_auth_ldap'] = {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'handlers': ['console'],
|
'handlers': DEFAULT_LOG_HANDLER,
|
||||||
}
|
}
|
||||||
|
|
||||||
# get global options from dict and use ldap.OPT_* as keys and values
|
# get global options from dict and use ldap.OPT_* as keys and values
|
||||||
|
@ -55,6 +55,9 @@ db_logging: False
|
|||||||
# Enable writing a log file, or use the environment variable INVENTREE_WRITE_LOG
|
# Enable writing a log file, or use the environment variable INVENTREE_WRITE_LOG
|
||||||
write_log: False
|
write_log: False
|
||||||
|
|
||||||
|
# Enable writing logs to the console (stdout), or use the environment variable INVENTREE_CONSOLE_LOG
|
||||||
|
console_log: True
|
||||||
|
|
||||||
# Select default system language , or use the environment variable INVENTREE_LANGUAGE
|
# Select default system language , or use the environment variable INVENTREE_LANGUAGE
|
||||||
language: en-us
|
language: en-us
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user