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
:
log
log_debug
log_warning
log_error
log_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
Close
Hashes for django-logbasecommand-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74fb950a0d5f535403cd6f522e2d5729f1beda430e31008f398faad2c2877205 |
|
MD5 | 4f6c90ff551e0ea681bd1a1399c1c4c4 |
|
BLAKE2b-256 | ab36f1a04ae094dfa96b0e1aab83580a697143a50b63e55ab1f700181ccdf771 |
Close
Hashes for django_logbasecommand-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8973179e8ac567191f7f63b74689d1bc505b252fb7a7facddedf084bdf34c19e |
|
MD5 | 06793cde8ad79e3fe164d064dc206e5f |
|
BLAKE2b-256 | 4e8e5c8f903ebc531d2d879bb088aa267383afc1b6a8ff7fa7a3cebc13354cc1 |