Skip to main content

A Django logger that logs to MongoDB using MongoEngine.

Project description

Django MongoEngine Logger

A Django logger that logs to MongoDB using MongoEngine.

Installation

pip install django-mongo-logger
pip install mongoengine

Usage

To configure the logger, add the following to your settings.py file:

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "verbose": {
            "format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
        },
        "simple": {
            "format": "%(levelname)s %(message)s",
        },
    },
    "handlers": {
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "verbose",
        },
        "mongo": {
            "level": "DEBUG",
            "class": "django_mongoengine_logger.logging.MongoDBHandler",
            "log_document_path": "django_mongoengine_logger.documents.LogDocument", # path to you mongo engine log Document if not provided if not provided package will use default Document
        },
    },
    "loggers": {
        "django": {
            "handlers": ["console"],
            "level": "INFO",
            "propagate": True,
        },
        "mongo_log": {
            "handlers": ["mongo"],
            "level": "DEBUG",
            "propagate": False,
        },
    },
}

log save in mongodb database with default name of django_logs

Example

import logging

logger = logging.getLogger('mongo_log')
logger.debug('This is a debug message')
logger.info('This is an info message')
logger.error('This is an error message')

# you can pass json string to log message too

import json
logger = logging.getLogger(json.dumps({"message": 'mongo_log'}))
logger.debug(json.dumps({"message":'This is a debug message'}))
logger.info(json.dumps({"message":'This is an info message'}))
logger.error(json.dumps({"message":'This is an error message'}))

License

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

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Acknowledgements

any contributors to this project will be appreciated.

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

django_mongoengine_logger-0.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

django_mongoengine_logger-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file django_mongoengine_logger-0.1.1.tar.gz.

File metadata

  • Download URL: django_mongoengine_logger-0.1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Windows/10

File hashes

Hashes for django_mongoengine_logger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6b48d833ed4903e12e88ad79067e16d7eccc3d7fe8d7b12ba169c60689f790cd
MD5 ab43fb5ade44498623cf3c203a06a42d
BLAKE2b-256 a3654b9146d9b5373629b28f6c675dd66c2b394ac16168b1adead068f7d1d43a

See more details on using hashes here.

File details

Details for the file django_mongoengine_logger-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_mongoengine_logger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9af97062deceb6438212b674c23b4055e881275ff3ef74feb9a93fa61ff6736
MD5 8b0b8ac75c5a39c827b453f1ecaacd20
BLAKE2b-256 93c71418220d797ac0b09a02986081515fea38669322095009630b6c5ce3931e

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