Skip to main content

Loki logger for Django applications

Project description

Loki Django Logger

This package provides a lightweight logging solution for Django applications that sends logs to Grafana Loki with gzip compression for improved performance.

Installation

pip install loki-django-logger

Configuration

  1. Add the logger to your Django settings.

In your settings.py:

from loki_django_logger.logger import configure_logger

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "loki": {
            "class": "loki_django_logger.handler.AsyncGzipLokiHandler",
            "loki_url": "http://localhost:3100",
        },
    },
    "loggers": {
        "django": {
            "handlers": ["loki"],
            "level": "INFO",
            "propagate": True,
        },
    },
}
  1. Install Loki if not already available:
docker run -d --name=loki -p 3100:3100 grafana/loki:latest
  1. Run your Django application and monitor the logs in Loki.

Example Usage

In your Django views or tasks:

import logging
logger = logging.getLogger("django")

def sample_view(request):
    logger.info("Sample log message sent to Loki")
    return JsonResponse({"message": "Logged successfully!"})

Testing

To run tests:

pytest tests/

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

loki_django_logger-1.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

loki_django_logger-1.0.5-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file loki_django_logger-1.0.5.tar.gz.

File metadata

  • Download URL: loki_django_logger-1.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for loki_django_logger-1.0.5.tar.gz
Algorithm Hash digest
SHA256 56567ad931b28abd1501971cddcc5f9adf240d75454e68b78e4e39d23f5717a0
MD5 2ad477d99868596fdfde1a6ffab8d46c
BLAKE2b-256 20c990da44c2afdc146801d0ac0f72d9f7351f70df2dea99c33eaa77d3539671

See more details on using hashes here.

File details

Details for the file loki_django_logger-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for loki_django_logger-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4b7a7579d41613ac4f0be169f221c5326d0eec3088ac4fc6e7c40354cb2bedf4
MD5 18db83a431e24322d8229ea74e1177ce
BLAKE2b-256 f4e7452b9756c86d7e98591ab3e15ee6d0f2f8cedee85baf7d02fc855d9809dc

See more details on using hashes here.

Supported by

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