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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae247a19a399bd0aa04b710df766efb4fbcc3a5bad159967555905698aa702e |
|
MD5 | d59b85d085328a37c04ed1092dd51dc1 |
|
BLAKE2b-256 | fa5f623b6ed61a880690a7e4bfac841848d1ac2974d27c581de8417504704330 |
Close
Hashes for django_logbasecommand-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff9d5b7ece4af0399db1fdbe06f80864f008305e522c4a8321177b9ec61d911e |
|
MD5 | 1e715c6079d74f0bb1a4cc243e128163 |
|
BLAKE2b-256 | aee311b5140289cd73668a414f97613b9a273b4130cb1379ab848e028f82778b |