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

Metadata

Release files for django-logbasecommand 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-logbasecommand 0.0.5
File Size Uploaded
django_logbasecommand-0.0.5.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-logbasecommand 0.0.5
File Interpreter ABI Platform
django_logbasecommand-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / django_logbasecommand-0.0.5.tar.gz

Download URL django_logbasecommand-0.0.5.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ada5ccdbe3a43652520da85697b7db4b58a5ed53e0abdf171947fe30955a19c3
BLAKE2b-256 checksum
How to use checksums
7d1f0b067c8f2b58bc1d1b85a70b5aec5e98394421b22ff36d3c0316b79b0cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / django_logbasecommand-0.0.5-py3-none-any.whl

Download URL django_logbasecommand-0.0.5-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b34cadb0cac6fb8f1ada7976a153ee19651d5f65866cbf3bb3911e96ab4cd36
BLAKE2b-256 checksum
How to use checksums
fed07a9630bc8ea71740528c0d79b48bafbc3b284305bbfc962e1b99a39f879c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page