Skip to main content

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,
        },
    },
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_logbasecommand-0.0.5.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_logbasecommand-0.0.5-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for django_logbasecommand-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ada5ccdbe3a43652520da85697b7db4b58a5ed53e0abdf171947fe30955a19c3
MD5 a3e6bec546646b3f43fa45f17b3bf812
BLAKE2b-256 7d1f0b067c8f2b58bc1d1b85a70b5aec5e98394421b22ff36d3c0316b79b0cac

See more details on using hashes here.

File details

Details for the file django_logbasecommand-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_logbasecommand-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9b34cadb0cac6fb8f1ada7976a153ee19651d5f65866cbf3bb3911e96ab4cd36
MD5 912cbd6edcc43a2f012b503fa77231ca
BLAKE2b-256 fed07a9630bc8ea71740528c0d79b48bafbc3b284305bbfc962e1b99a39f879c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page