Minimal package to add logging helpers to Django management commands
Project description
django-logbasecommand
Minimal package to add logging helpers to Django management commands
Usage
Replace
from django.core.management.base import BaseCommand
class YourCommand(BaseCommand):
with
from logbasecommand.base import LogBaseCommand
class LogBaseCommand(BaseCommand):
and now you can use the drop-in methods to replace self.stdout/self.stderr:
loglog_debuglog_warninglog_errorlog_exception
Or access self.logger directly.
All command logger names are derived from the command module name and prefixed with logbasecommand.base (by default, use LOGBASECOMMAND_PREFIX setting to change it), so logging can be configured from your project settings.py, with LOGGING, ie (full example, check the loggers part):
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {'()': 'django.utils.log.RequireDebugFalse'},
'require_debug_true': {'()': 'django.utils.log.RequireDebugTrue'},
},
'formatters': {
'verbose': {'format': '[%(asctime)s] [%(process)s] [%(levelname)s] [%(name)s] %(message)s'},
'minimal': {'format': '[%(levelname)s] [%(name)s] %(message)s'},
},
'handlers': {
'console': {
'level': 'INFO',
'filters': ['require_debug_false'],
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
'console_debug': {
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
'console_minimal': {
'level': 'INFO',
'filters': ['require_debug_false'],
'class': 'logging.StreamHandler',
'formatter': 'minimal',
},
'console_debug_minimal': {
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
'formatter': 'minimal',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
},
},
'loggers': {
'': {'handlers': ['console', 'console_debug'], 'level': 'INFO', 'propagate': True},
'logbasecommand.base': {
'handlers': ['console_minimal', 'console_debug_minimal'],
'level': 'DEBUG',
'propagate': False,
},
},
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_logbasecommand-0.0.5.tar.gz.
File metadata
- Download URL: django_logbasecommand-0.0.5.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ada5ccdbe3a43652520da85697b7db4b58a5ed53e0abdf171947fe30955a19c3
|
|
| MD5 |
a3e6bec546646b3f43fa45f17b3bf812
|
|
| BLAKE2b-256 |
7d1f0b067c8f2b58bc1d1b85a70b5aec5e98394421b22ff36d3c0316b79b0cac
|
File details
Details for the file django_logbasecommand-0.0.5-py3-none-any.whl.
File metadata
- Download URL: django_logbasecommand-0.0.5-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b34cadb0cac6fb8f1ada7976a153ee19651d5f65866cbf3bb3911e96ab4cd36
|
|
| MD5 |
912cbd6edcc43a2f012b503fa77231ca
|
|
| BLAKE2b-256 |
fed07a9630bc8ea71740528c0d79b48bafbc3b284305bbfc962e1b99a39f879c
|