django-automated-logging


Namedjango-automated-logging JSON
Version 6.2.2 PyPI version JSON
download
home_pagehttps://github.com/indietyp/django-automated-logging
SummaryDjango Database Based Automated Logging - finally solved and done in a proper way.
upload_time2024-03-18 17:52:18
maintainer
docs_urlNone
authorBilal Mahmoud
requires_python>=3.10,<4
licenseMIT
keywords django automation tools backend logging
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Django Database Based Automated Logging

[![](https://badgen.net/pypi/v/django-automated-logging)](https://pypi.python.org/pypi?name=django-automated-logging)
[![](https://badgen.net/pypi/license/django-automated-logging)](https://pypi.python.org/pypi?name=django-automated-logging)
[![](https://img.shields.io/pypi/status/django-automated-logging.svg)](https://pypi.python.org/pypi?name=django-automated-logging)
[![](https://badgen.net/pypi/python/django-automated-logging)](https://pypi.python.org/pypi?name=django-automated-logging)
[![Build Status](https://www.travis-ci.com/indietyp/django-automated-logging.svg?branch=master)](https://www.travis-ci.com/indietyp/django-automated-logging)
[![](https://coveralls.io/repos/github/indietyp/django-automated-logging/badge.svg?branch=master)](https://coveralls.io/github/indietyp/django-automated-logging?branch=master)
[![](https://api.codacy.com/project/badge/Grade/96fdb764fc34486399802b2f8267efcc)](https://www.codacy.com/app/bilalmahmoud/django-automated-logging?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=indietyp/django-automated-logging&amp;utm_campaign=Badge_Grade)
[![](https://img.shields.io/badge/Support%20the%20Project-PayPal-green.svg)](https://paypal.me/indietyp/5)

**Notice:** Most of this will be moved into a wiki.

## What is Django-Automated-Logging (DAL)?

TL;DR: DAL is a package to **automatically** track changes in your project, ranging
from simple logging messages, to model changes or requests done by users.

You can decide what you want to do and how.
DAL allows fine-grained customization and filtering with various methods.

### Introduction

Django Fully Automated Logging - **finally** solved and done properly.

How to install?
`pip install django-automated-logging` or `poetry add django-automated-logging`

### What is the purpose?

The goal of DAL is to provide an easy, accessible and DRY way to log the inner working of you applications.
Ultimately giving you the chance to easily see what is happening without excessive manual print/logging statements.

The application uses minimal requirements and is performant.

### How does it work?

The application facilitates the built-in logging mechanic
by providing a custom handler, that just needs to be added to the `LOGGING` configuration.

DAL uses native Django signals to know what is happening behind the scenes without injecting custom code.

### Minimal Setup

You can also configure DAL to only log to a file and not to a database.
You just need to enable DAL and not include the custom logging handler.

## Detailed Information

### Features

1. Easy Setup
2. Extensible
3. Feature-Rich
4. Completely Automated
5. Built-In Database Logger
6. No custom code needs to be inserted into your codebase
7. Can capture logging messages unrelated to the package itself
8. Only does what it needs to do, no extra bells and whistles.

### Setup

Initial Configuration is via your projects `settings.py`

1. `INSTALLED_APPS` append: `'automated_logging'`
2. `MIDDLEWARE` append: `'automated_logging.middleware.AutomatedLoggingMiddleware'`
3. `LOGGING` section `handlers` add:
    ```python
       'db': {
           'level': 'INFO',
           'class': 'automated_logging.handlers.DatabaseHandler',
       }
    ```
4. `LOGGING` section `loggers` add: (only required if database logging desired)
    ```python
       'automated_logging': {
           'level': 'INFO',
           'handlers': ['db'],
           'propagate': True,
       },
       'django': {
           'level': 'INFO',
           'handlers': ['db'],
           'propagate': True,
       },
    ```
5. execute: `python manage.py migrate automated_logging`

`LOGGING` configuration details are just recommendations.

### Migrations

When migrating from 5.x.x to 6.x.x the logs are converted between the two versions.
This can take a while, and depending on the size of your database might lead to `'Server has gone away’` errors on
MySQL.
You can increase the `max_allowed_packet` variable in your MySQL configuration to fix this, or
set `DAL_SKIP_CONVERSION = true` as an environment variable to skip the conversion.

### Configuration

Further configuration can be done via the variable `AUTOMATED_LOGGING`. The defaults are:

```python
AUTOMATED_LOGGING = {
    "globals": {
        "exclude": {
            "applications": [
                "plain:contenttypes",
                "plain:admin",
                "plain:basehttp",
                "glob:session*",
                "plain:migrations",
            ]
        }
    },
    "model": {
        "detailed_message": True,
        "exclude": {"applications": [], "fields": [], "models": [], "unknown": False},
        "loglevel": 20,
        "mask": [],
        "max_age": None,
        "performance": False,
        "snapshot": False,
        "user_mirror": False,
    },
    "modules": ["request", "unspecified", "model"],
    "request": {
        "data": {
            "content_types": ["application/json"],
            "enabled": [],
            "ignore": [],
            "mask": ["password"],
            "query": False,
        },
        "exclude": {
            "applications": [],
            "methods": ["GET"],
            "status": [200],
            "unknown": False,
        },
        "ip": True,
        "loglevel": 20,
        "max_age": None,
    },
    "unspecified": {
        "exclude": {"applications": [], "files": [], "unknown": False},
        "loglevel": 20,
        "max_age": None,
    },
}
```

You can always inspect the current default configuration by doing:

```python
from pprint import pprint
from automated_logging.settings import default
from automated_logging.helpers import namedtuple2dict

pprint(namedtuple2dict(default))
```

**Recommendation:** include the `globals` application defaults as those modules can be particularly verbose or be
duplicates.

There are *three* different independent modules available `request` (for request logging), `unspecified` (for general
logging messages), and `models` (for model changes).
They can be enabled and disabled by including them in the `modules` configuration.

The `loglevel` setting indicates the severity for the logging messages sent from the module.
`INFO (20)` or `DEBUG (10)` is the right call for most cases.

*New in 6.x.x:* Saving can be batched via the `batch` setting for the handler.

*New in 6.x.x:* Saving can be threaded by `thread: True` for the handler settings. **This is highly experimental**

*New in 6.x.x:* every field in `exclude` can be either be a `glob` (prefixing the string with `gl:`), a `regex` (
prefixing the string with `re:`) or plain (prefixing the string with `pl:`). The default is `glob`.

### Decorators

You can explicitly exclude or include views/models, by using the new decorators.

```python
from automated_logging.decorators import include_view, include_model, exclude_view, exclude_model


@include_view(methods=None)
@exclude_view(methods=[])
def view(request):
    pass


@include_model(operations=None, fields=None)
@exclude_model(operations=[], fields=[])
class ExampleModel:
    pass
```

`include` *always* takes precedence over `exclude`, if you use multiple `include` or `exclude` instead of overwriting
they will *update/extend* the previous definition.

`operations` can be either `create`, `modify`, `delete`. `fields` is a list model specific fields to be
included/excluded.
`methods` is a list methods to be included/excluded.

### Class-Based Configuration

Class-Based Configuration is done over a specific meta class `LoggingIgnore`. Decorators take precedence over
class-based configuration, but class-based configuration takes precedence over AUTOMATED_LOGGING configuration.

```python
class ExampleModel:
    class LoggingIgnore:
        complete = False
        fields = []
        operations = []
```

as described above `operations` and `fields` work the same way. `complete = True` means that a model is excluded no
matter what.

## Changelog

### Version 6.0.0

- **Added:** ``batch`` settings to the handler
- **Added:** decorators
- **Added:** class-based configuration
- **Added:** request and response bodies can now be saved
- **Added:** regex, glob matching for settings
- **Updated:** settings
- **Updated:** models
- **Updated:** to current django version (2.2, 3.0, 3.1)
- **Updated:** DAL no longer stores internal information directly, but now has a custom _meta object injected.
- **Updated:** project now uses black for formatting
- **Updated:** internals were completely rewritten for greater maintainability and speed.
- **Fixed:** https://github.com/indietyp/django-automated-logging/issues/1
- **Fixed:** https://github.com/indietyp/django-automated-logging/issues/2
- **Moved:** `max_age` is now part of the `settings.py` configuration.

### Version 5.0.0

- **Added:** ``maxage`` handler setting to automatically remove database entries after a certain amount of time.
- **Added:** query string in requests can now be enabled/disabled (are now disabled by default)
- **Fixed:** Value and URI could be longer than 255 characters. DAL would throw an exception. This is fixed.

## Roadmap

### Version 6.1.x

- [ ] archive options
- [ ] decorators greater flexibility
- [ ] wiki -> documentation
- [ ] make django-ipware optional via extras
- [ ] and more!

### Version 7.x.x

- [ ] implementation of a git like versioning interface

### Version 8.x.x

- [ ] temporary world domination

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/indietyp/django-automated-logging",
    "name": "django-automated-logging",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4",
    "maintainer_email": "",
    "keywords": "django,automation,tools,backend,logging",
    "author": "Bilal Mahmoud",
    "author_email": "bilalmahmoud@posteo.net",
    "download_url": "https://files.pythonhosted.org/packages/48/0f/c6784344298fb74b330045da9fe5798a6ff45bf4a4bb73b9a68a870d4352/django_automated_logging-6.2.2.tar.gz",
    "platform": null,
    "description": "# Django Database Based Automated Logging\n\n[![](https://badgen.net/pypi/v/django-automated-logging)](https://pypi.python.org/pypi?name=django-automated-logging)\n[![](https://badgen.net/pypi/license/django-automated-logging)](https://pypi.python.org/pypi?name=django-automated-logging)\n[![](https://img.shields.io/pypi/status/django-automated-logging.svg)](https://pypi.python.org/pypi?name=django-automated-logging)\n[![](https://badgen.net/pypi/python/django-automated-logging)](https://pypi.python.org/pypi?name=django-automated-logging)\n[![Build Status](https://www.travis-ci.com/indietyp/django-automated-logging.svg?branch=master)](https://www.travis-ci.com/indietyp/django-automated-logging)\n[![](https://coveralls.io/repos/github/indietyp/django-automated-logging/badge.svg?branch=master)](https://coveralls.io/github/indietyp/django-automated-logging?branch=master)\n[![](https://api.codacy.com/project/badge/Grade/96fdb764fc34486399802b2f8267efcc)](https://www.codacy.com/app/bilalmahmoud/django-automated-logging?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=indietyp/django-automated-logging&amp;utm_campaign=Badge_Grade)\n[![](https://img.shields.io/badge/Support%20the%20Project-PayPal-green.svg)](https://paypal.me/indietyp/5)\n\n**Notice:** Most of this will be moved into a wiki.\n\n## What is Django-Automated-Logging (DAL)?\n\nTL;DR: DAL is a package to **automatically** track changes in your project, ranging\nfrom simple logging messages, to model changes or requests done by users.\n\nYou can decide what you want to do and how.\nDAL allows fine-grained customization and filtering with various methods.\n\n### Introduction\n\nDjango Fully Automated Logging - **finally** solved and done properly.\n\nHow to install?\n`pip install django-automated-logging` or `poetry add django-automated-logging`\n\n### What is the purpose?\n\nThe goal of DAL is to provide an easy, accessible and DRY way to log the inner working of you applications.\nUltimately giving you the chance to easily see what is happening without excessive manual print/logging statements.\n\nThe application uses minimal requirements and is performant.\n\n### How does it work?\n\nThe application facilitates the built-in logging mechanic\nby providing a custom handler, that just needs to be added to the `LOGGING` configuration.\n\nDAL uses native Django signals to know what is happening behind the scenes without injecting custom code.\n\n### Minimal Setup\n\nYou can also configure DAL to only log to a file and not to a database.\nYou just need to enable DAL and not include the custom logging handler.\n\n## Detailed Information\n\n### Features\n\n1. Easy Setup\n2. Extensible\n3. Feature-Rich\n4. Completely Automated\n5. Built-In Database Logger\n6. No custom code needs to be inserted into your codebase\n7. Can capture logging messages unrelated to the package itself\n8. Only does what it needs to do, no extra bells and whistles.\n\n### Setup\n\nInitial Configuration is via your projects `settings.py`\n\n1. `INSTALLED_APPS` append: `'automated_logging'`\n2. `MIDDLEWARE` append: `'automated_logging.middleware.AutomatedLoggingMiddleware'`\n3. `LOGGING` section `handlers` add:\n    ```python\n       'db': {\n           'level': 'INFO',\n           'class': 'automated_logging.handlers.DatabaseHandler',\n       }\n    ```\n4. `LOGGING` section `loggers` add: (only required if database logging desired)\n    ```python\n       'automated_logging': {\n           'level': 'INFO',\n           'handlers': ['db'],\n           'propagate': True,\n       },\n       'django': {\n           'level': 'INFO',\n           'handlers': ['db'],\n           'propagate': True,\n       },\n    ```\n5. execute: `python manage.py migrate automated_logging`\n\n`LOGGING` configuration details are just recommendations.\n\n### Migrations\n\nWhen migrating from 5.x.x to 6.x.x the logs are converted between the two versions.\nThis can take a while, and depending on the size of your database might lead to `'Server has gone away\u2019` errors on\nMySQL.\nYou can increase the `max_allowed_packet` variable in your MySQL configuration to fix this, or\nset `DAL_SKIP_CONVERSION = true` as an environment variable to skip the conversion.\n\n### Configuration\n\nFurther configuration can be done via the variable `AUTOMATED_LOGGING`. The defaults are:\n\n```python\nAUTOMATED_LOGGING = {\n    \"globals\": {\n        \"exclude\": {\n            \"applications\": [\n                \"plain:contenttypes\",\n                \"plain:admin\",\n                \"plain:basehttp\",\n                \"glob:session*\",\n                \"plain:migrations\",\n            ]\n        }\n    },\n    \"model\": {\n        \"detailed_message\": True,\n        \"exclude\": {\"applications\": [], \"fields\": [], \"models\": [], \"unknown\": False},\n        \"loglevel\": 20,\n        \"mask\": [],\n        \"max_age\": None,\n        \"performance\": False,\n        \"snapshot\": False,\n        \"user_mirror\": False,\n    },\n    \"modules\": [\"request\", \"unspecified\", \"model\"],\n    \"request\": {\n        \"data\": {\n            \"content_types\": [\"application/json\"],\n            \"enabled\": [],\n            \"ignore\": [],\n            \"mask\": [\"password\"],\n            \"query\": False,\n        },\n        \"exclude\": {\n            \"applications\": [],\n            \"methods\": [\"GET\"],\n            \"status\": [200],\n            \"unknown\": False,\n        },\n        \"ip\": True,\n        \"loglevel\": 20,\n        \"max_age\": None,\n    },\n    \"unspecified\": {\n        \"exclude\": {\"applications\": [], \"files\": [], \"unknown\": False},\n        \"loglevel\": 20,\n        \"max_age\": None,\n    },\n}\n```\n\nYou can always inspect the current default configuration by doing:\n\n```python\nfrom pprint import pprint\nfrom automated_logging.settings import default\nfrom automated_logging.helpers import namedtuple2dict\n\npprint(namedtuple2dict(default))\n```\n\n**Recommendation:** include the `globals` application defaults as those modules can be particularly verbose or be\nduplicates.\n\nThere are *three* different independent modules available `request` (for request logging), `unspecified` (for general\nlogging messages), and `models` (for model changes).\nThey can be enabled and disabled by including them in the `modules` configuration.\n\nThe `loglevel` setting indicates the severity for the logging messages sent from the module.\n`INFO (20)` or `DEBUG (10)` is the right call for most cases.\n\n*New in 6.x.x:* Saving can be batched via the `batch` setting for the handler.\n\n*New in 6.x.x:* Saving can be threaded by `thread: True` for the handler settings. **This is highly experimental**\n\n*New in 6.x.x:* every field in `exclude` can be either be a `glob` (prefixing the string with `gl:`), a `regex` (\nprefixing the string with `re:`) or plain (prefixing the string with `pl:`). The default is `glob`.\n\n### Decorators\n\nYou can explicitly exclude or include views/models, by using the new decorators.\n\n```python\nfrom automated_logging.decorators import include_view, include_model, exclude_view, exclude_model\n\n\n@include_view(methods=None)\n@exclude_view(methods=[])\ndef view(request):\n    pass\n\n\n@include_model(operations=None, fields=None)\n@exclude_model(operations=[], fields=[])\nclass ExampleModel:\n    pass\n```\n\n`include` *always* takes precedence over `exclude`, if you use multiple `include` or `exclude` instead of overwriting\nthey will *update/extend* the previous definition.\n\n`operations` can be either `create`, `modify`, `delete`. `fields` is a list model specific fields to be\nincluded/excluded.\n`methods` is a list methods to be included/excluded.\n\n### Class-Based Configuration\n\nClass-Based Configuration is done over a specific meta class `LoggingIgnore`. Decorators take precedence over\nclass-based configuration, but class-based configuration takes precedence over AUTOMATED_LOGGING configuration.\n\n```python\nclass ExampleModel:\n    class LoggingIgnore:\n        complete = False\n        fields = []\n        operations = []\n```\n\nas described above `operations` and `fields` work the same way. `complete = True` means that a model is excluded no\nmatter what.\n\n## Changelog\n\n### Version 6.0.0\n\n- **Added:** ``batch`` settings to the handler\n- **Added:** decorators\n- **Added:** class-based configuration\n- **Added:** request and response bodies can now be saved\n- **Added:** regex, glob matching for settings\n- **Updated:** settings\n- **Updated:** models\n- **Updated:** to current django version (2.2, 3.0, 3.1)\n- **Updated:** DAL no longer stores internal information directly, but now has a custom _meta object injected.\n- **Updated:** project now uses black for formatting\n- **Updated:** internals were completely rewritten for greater maintainability and speed.\n- **Fixed:** https://github.com/indietyp/django-automated-logging/issues/1\n- **Fixed:** https://github.com/indietyp/django-automated-logging/issues/2\n- **Moved:** `max_age` is now part of the `settings.py` configuration.\n\n### Version 5.0.0\n\n- **Added:** ``maxage`` handler setting to automatically remove database entries after a certain amount of time.\n- **Added:** query string in requests can now be enabled/disabled (are now disabled by default)\n- **Fixed:** Value and URI could be longer than 255 characters. DAL would throw an exception. This is fixed.\n\n## Roadmap\n\n### Version 6.1.x\n\n- [ ] archive options\n- [ ] decorators greater flexibility\n- [ ] wiki -> documentation\n- [ ] make django-ipware optional via extras\n- [ ] and more!\n\n### Version 7.x.x\n\n- [ ] implementation of a git like versioning interface\n\n### Version 8.x.x\n\n- [ ] temporary world domination\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django Database Based Automated Logging - finally solved and done in a proper way.",
    "version": "6.2.2",
    "project_urls": {
        "Homepage": "https://github.com/indietyp/django-automated-logging",
        "Repository": "https://github.com/indietyp/django-automated-logging"
    },
    "split_keywords": [
        "django",
        "automation",
        "tools",
        "backend",
        "logging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04d98d9e46541f36519c7bd18127990b09a230fbb0356b98cc92a1cbd04dcda0",
                "md5": "24d462d802668531f8285397993371be",
                "sha256": "b23180bb64a6643b1b8529530fa279c4d3b6465ac4fb3331b44dc9e0f2887d0a"
            },
            "downloads": -1,
            "filename": "django_automated_logging-6.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "24d462d802668531f8285397993371be",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4",
            "size": 66185,
            "upload_time": "2024-03-18T17:52:16",
            "upload_time_iso_8601": "2024-03-18T17:52:16.015395Z",
            "url": "https://files.pythonhosted.org/packages/04/d9/8d9e46541f36519c7bd18127990b09a230fbb0356b98cc92a1cbd04dcda0/django_automated_logging-6.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "480fc6784344298fb74b330045da9fe5798a6ff45bf4a4bb73b9a68a870d4352",
                "md5": "d4595bff8aeaf8e7e7eeb1d2521c68f1",
                "sha256": "1dc81dac739da360934862a89384ecb07677f1c16637ec947c5771ab7216eb7e"
            },
            "downloads": -1,
            "filename": "django_automated_logging-6.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d4595bff8aeaf8e7e7eeb1d2521c68f1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4",
            "size": 47198,
            "upload_time": "2024-03-18T17:52:18",
            "upload_time_iso_8601": "2024-03-18T17:52:18.467959Z",
            "url": "https://files.pythonhosted.org/packages/48/0f/c6784344298fb74b330045da9fe5798a6ff45bf4a4bb73b9a68a870d4352/django_automated_logging-6.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-18 17:52:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "indietyp",
    "github_project": "django-automated-logging",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "django-automated-logging"
}
        
Elapsed time: 4.59470s