Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/chore #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 63 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
29 changes: 29 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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 = [
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions docs/settings.rst
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Loading