diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 75f4eab1eb..cc21662be9 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -109,6 +109,14 @@ LOGGING = { }, } +# Optionally add database-level logging +if get_setting('INVENTREE_DB_LOGGING', 'db_logging', False): + LOGGING['loggers'] = { + 'django.db.backends': { + 'level': log_level or 'DEBUG', + }, + } + # Get a logger instance for this setup file logger = logging.getLogger("inventree") diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 00c0f4dad8..8f22037da6 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -69,6 +69,10 @@ debug: True # Options: DEBUG / INFO / WARNING / ERROR / CRITICAL log_level: WARNING +# Enable database-level logging +# Use the environment variable INVENTREE_DB_LOGGING +db_logging: False + # Select default system language (default is 'en-us') # Use the environment variable INVENTREE_LANGUAGE language: en-us diff --git a/docker.dev.env b/docker.dev.env index e6f3b2c678..a35f402a9c 100644 --- a/docker.dev.env +++ b/docker.dev.env @@ -4,6 +4,7 @@ # Set DEBUG to True for a development setup INVENTREE_DEBUG=True INVENTREE_LOG_LEVEL=INFO +INVENTREE_DB_LOGGING=False # Database configuration options # Note: The example setup is for a PostgreSQL database (change as required) diff --git a/docs/docs/start/config.md b/docs/docs/start/config.md index 3e4be33865..840d9045ce 100644 --- a/docs/docs/start/config.md +++ b/docs/docs/start/config.md @@ -53,6 +53,7 @@ The following basic options are available: | --- | --- | --- | --- | | INVENTREE_DEBUG | debug | Enable [debug mode](./intro.md#debug-mode) | True | | INVENTREE_LOG_LEVEL | log_level | Set level of logging to terminal | WARNING | +| INVENTREE_DB_LOGGING | db_logging | Enable logging of database messages | False | | INVENTREE_TIMEZONE | timezone | Server timezone | UTC | | ADMIN_URL | admin_url | URL for accessing [admin interface](../settings/admin.md) | admin | | INVENTREE_LANGUAGE | language | Default language | en-us |