diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 898970b..55ef99d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,44 +3,82 @@ repos: rev: v4.4.0 hooks: - id: trailing-whitespace - exclude: (tests/|docs/).* + exclude: (migrations/|tests/|docs/).* - id: end-of-file-fixer - exclude: (tests/|docs/).* - - id: check-yaml - exclude: (tests/|docs/).* + exclude: (migrations/|tests/|docs/).* - id: check-added-large-files - exclude: (tests/|docs/).* + exclude: (migrations/|tests/|docs/).* - id: check-case-conflict - exclude: (tests/|docs/).* + exclude: (migrations/|tests/|docs/).* - id: check-merge-conflict - exclude: (tests/|docs/).* + exclude: (migrations/|tests/|docs/).* - id: check-docstring-first - exclude: (tests/|docs/).* - - - - repo: https://github.com/psf/black - rev: 24.4.2 - hooks: - - id: black - exclude: (tests/|docs/).* - + exclude: (migrations/|tests/|docs/).* - repo: https://github.com/pre-commit/mirrors-isort rev: v5.10.1 hooks: - id: isort - exclude: (tests/|docs/).* + exclude: (migrations/|tests/|docs/).* + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + args: ["--config=pyproject.toml"] + exclude: (migrations/|tests/|docs/).* - repo: https://github.com/commitizen-tools/commitizen rev: v3.28.0 hooks: - id: commitizen - exclude: (tests/|docs/).* - -# - repo: https://github.com/PyCQA/bandit -# rev: 1.7.4 -# hooks: -# - id: bandit -# args: [ "-c pyproject.toml" ] -# additional_dependencies: [ "toml" ] + exclude: (migrations/|tests/|docs/).* + + - repo: https://github.com/PyCQA/bandit + rev: 1.7.4 + hooks: + - id: bandit + args: ["-c", "pyproject.toml", "-r", "."] + additional_dependencies: [ "bandit[toml]" ] + exclude: (migrations/|tests/|docs/).* + + - repo: https://github.com/PyCQA/docformatter + rev: v1.7.5 + hooks: + - id: docformatter + args: ["--in-place", "--recursive", "--blank"] + exclude: (migrations/|tests/|docs/).* + + - repo: https://github.com/rstcheck/rstcheck + rev: "v6.2.4" + hooks: + - id: rstcheck + args: ["--report-level=warning"] + files: ^(docs/(.*/)*.*\.rst) + additional_dependencies: [Sphinx==6.2.1] + + - repo: local + hooks: + - id: pytest + name: Pytest + entry: poetry run pytest -v + language: system + types: [python] + stages: [commit] + pass_filenames: false + always_run: true + + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + require_serial: true + args: + - "-rn" + - "-sn" + - "--rcfile=pyproject.toml" + files: ^django_logging/ + +ci: + skip: [pylint] diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..9dbd03e --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,29 @@ +# .readthedocs.yml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version, and other tools +build: + os: ubuntu-22.04 + tools: + python: "3.8" + +# Build documentation with Sphinx +sphinx: + configuration: docs/conf.py + +# Optionally build your docs in additional formats such as PDF and ePub +# formats: +# - pdf +# - epub + + +# Optional but recommended, declare the Python requirements required +# to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +python: + install: + - requirements: packages/requirements-dev.txt diff --git a/README.md b/README.md index e3da737..96fa5db 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The [`django_logging`](https://github.com/ARYAN-NIKNEZHAD/django_logging) is a D - Language: Python > 3.8 - Framework: Django > 4.2 - | +- ## Documentation @@ -77,7 +77,7 @@ Email notifier enabled: False. ``` -That's it! `django_logging` is ready to use with default settings. For further customization, refer to the Settings section +That's it! `django_logging` is ready to use with default settings. For further customization, refer to the [Settings](#settings) section ## Usage @@ -97,8 +97,10 @@ logger.error("This is an error message") logger.critical("This is a critical message") ``` These logs will be handled according to the configurations set up by `django_logging`, using either the default settings or any custom settings you've provided. -Request Logging Middleware -To log request information such as the request path, user, IP address, and user agent, add `django_logging`.middleware.RequestLogMiddleware to your MIDDLEWARE setting: + +2. **Request Logging Middleware** + +To log the detail of each request to the server and capture information such as the request path, user, IP address, and user agent, add `django_logging.middleware.RequestLogMiddleware` to your MIDDLEWARE setting: ```python MIDDLEWARE = [ @@ -108,7 +110,7 @@ MIDDLEWARE = [ ] ``` -This middleware will log request details at info level, here is an example with default format: +This middleware will log th request details at info level, here is an example with default format: ```shell INFO | 'datetime' | django_logging | Request Info: (request_path: /example-path, user: example_user, IP: 192.168.1.1, user_agent: Mozilla/5.0) @@ -150,7 +152,7 @@ logger = logging.getLogger(__name__) log_and_notify_admin(logger, logging.INFO, "This is a log message") ``` -You can also include additional request information in the email by passing an `extra` dictionary: +You can also include additional request information (`ip_address` and `browser_type`) in the email by passing an `extra` dictionary: ```python from django_logging.utils.log_email_notifier.log_and_notify import log_and_notify_admin import logging @@ -183,12 +185,7 @@ This command will attach the log directory and send a zip file to the provided e ## Settings -The `DJANGO_LOGGING` configuration allows you to customize various aspects of logging within your Django project. Below is a detailed description of each configurable option. - -**Configuration Options** -The settings are defined in the `DJANGO_LOGGING` dictionary in your -`settings.py` file. Here’s a breakdown of each option: -By default, `django_logging` uses a built-in configuration that requires no additional setup. However, you can customize the logging settings by adding a `DJANGO_LOGGING` configuration to your Django settings file. +By default, `django_logging` uses a built-in configuration that requires no additional setup. However, you can customize the logging settings by adding the `DJANGO_LOGGING` dictionary configuration to your Django `settings` file. Example configuration: ```python diff --git a/docs/settings.rst b/docs/settings.rst index e5c4054..a0aac53 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -1,16 +1,7 @@ Settings ======== -The `DJANGO_LOGGING` configuration allows you to customize various aspects of logging within your Django project. Below is a detailed description of each configurable option. - -Configuration Options ----------------------- - -The settings are defined in the `DJANGO_LOGGING` dictionary in your `settings.py` file. Here’s a breakdown of each option: - - - -By default, `django_logging` uses a built-in configuration that requires no additional setup. However, you can customize the logging settings by adding a `DJANGO_LOGGING` configuration to your Django settings file. +By default, `django_logging` uses a built-in configuration that requires no additional setup. However, you can customize the logging settings by adding the `DJANGO_LOGGING` dictionary configuration to your Django `settings` file. Example configuration: diff --git a/docs/usage.rst b/docs/usage.rst index 6baf5aa..020a11a 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -23,7 +23,7 @@ Once `django_logging` is installed and added to your `INSTALLED_APPS`, you can s 2. **Request Logging Middleware** - To log request information such as the request path, user, IP address, and user agent, add `django_logging.middleware.RequestLogMiddleware` to your `MIDDLEWARE` setting: + To capture and log information of each request to the server, such as the request path, user, IP address, and user agent, add `django_logging.middleware.RequestLogMiddleware` to your `MIDDLEWARE` setting: .. code-block:: python @@ -33,7 +33,7 @@ Once `django_logging` is installed and added to your `INSTALLED_APPS`, you can s ... ] - This middleware will log request details at info level, here is an example with default format: + This middleware will log the request details at info level, here is an example with default format: .. code-block:: text