Skip to content

Commit

Permalink
⚡🔨📚🎨 refactor(docs): Improve rst docs readability and highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
MEHRSHAD-MIRSHEKARY committed Sep 6, 2024
1 parent 72a06b5 commit 6b6c12a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ with config_setup():

# the logging configuration will restore to what it was before, in here outside of with block
```
- Note: `AUTO_INITIALIZATION_ENABLE` must be set to `False` in the settings to use the context manager. If `AUTO_INITIALIZATION_ENABLE` is `True`, attempting to use the context manager will raise a `ValueError` with the message:
- Note: `AUTO_INITIALIZATION_ENABLE` must be set to `False` in the settings to use the context manager. If it is `True`, attempting to use the context manager will raise a `ValueError` with the message:
```
"You must set 'AUTO_INITIALIZATION_ENABLE' to False in DJANGO_LOGGING in your settings to use the context manager."
```
Expand Down
10 changes: 5 additions & 5 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Setting Up Your Environment
3. **Install Dependencies:**

Install the necessary dependencies using `Poetry`. If Poetry isn't installed on your machine, you can find installation instructions on the `Poetry website <https://python-poetry.org/docs/#installation>`_.
Install the necessary dependencies using ``Poetry``. If Poetry isn't installed on your machine, you can find installation instructions on the `Poetry website <https://python-poetry.org/docs/#installation>`_.

.. code-block:: bash
Expand All @@ -49,7 +49,7 @@ Setting Up Your Environment
Testing Your Changes
--------------------

We use `pytest` for running tests. Before submitting your changes, ensure that all tests pass:
We use ``pytest`` for running tests. Before submitting your changes, ensure that all tests pass:

.. code-block:: bash
Expand All @@ -60,14 +60,14 @@ If you’re adding a new feature or fixing a bug, don’t forget to write tests
Code Style Guidelines
----------------------

Maintaining a consistent code style is crucial. We use `black` for code formatting and `isort` for import sorting. Make sure your code adheres to these styles:
Maintaining a consistent code style is crucial. We use ``black`` for code formatting and ``isort`` for import sorting. Make sure your code adheres to these styles:

.. code-block:: bash
poetry run black .
poetry run isort .
For linting, `pylint` is used to enforce style and catch potential errors:
For linting, ``pylint`` is used to enforce style and catch potential errors:

.. code-block:: bash
Expand Down Expand Up @@ -123,7 +123,7 @@ Once your changes are ready, follow these steps to submit them:
3. **Open a Pull Request:**

Go to the original `django_logging` repository and open a pull request. Include a detailed description of your changes and link any related issues.
Go to the original `django_logging <https://github.com/Lazarus-org/django_logging>`_ repository and open a pull request. Include a detailed description of your changes and link any related issues.

4. **Respond to Feedback:**

Expand Down
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ Welcome to django_logging Documentation!
:target: https://pypi.org/project/dj-logging/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=yellow
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit

.. image:: https://img.shields.io/pypi/djversions/dj-logging
:target: https://pypi.org/project/dj-logging/
:alt: Supported Django versions

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=yellow
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit

.. image:: https://img.shields.io/github/issues/ARYAN-NIKNEZHAD/django_logging
:target: https://github.com/lazarus-org/django_logging/issues
:alt: Open Issues
Expand Down
14 changes: 7 additions & 7 deletions docs/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Getting Started with `django_logging` is simple. Follow these steps to get up an
2. **Add to Installed Apps**

Add `django_logging` to your `INSTALLED_APPS` in your Django settings file:
Add `django_logging` to your ``INSTALLED_APPS`` in your Django settings file:

.. code-block::
Expand Down Expand Up @@ -45,12 +45,12 @@ when the server starts, you'll see an initialization message like this in your *
By default, django_logging will log each level to its own file:

- DEBUG : `logs/debug.log`
- INFO : `logs/info.log`
- WARNING : `logs/warning.log`
- ERROR : `logs/error.log`
- CRITICAL : `logs/critical.log`
- DEBUG : ``logs/debug.log``
- INFO : ``logs/info.log``
- WARNING : ``logs/warning.log``
- ERROR : ``logs/error.log``
- CRITICAL : ``logs/critical.log``

In addition, logs will be displayed in **colorized** mode in the `console`, making it easier to distinguish between different log levels.
In addition, logs will be displayed in **colorized** mode in the ``console``, making it easier to distinguish between different log levels.

That's it! `django_logging` is ready to use. For further customization, refer to the :doc:`Settings <settings>`.
4 changes: 2 additions & 2 deletions docs/rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Available Roles

2. **Request Logging Role**

The Request Logging Role is specifically designed to log HTTP request details. This role captures information such as the request path, user, IP address, and user agent.
The Request Logging Role is specifically designed to log HTTP request details. This role captures information such as the ``request path``, ``user``, ``IP address``, and ``user agent``.

**Key Features:**
- Logs details of incoming requests.
Expand Down Expand Up @@ -54,7 +54,7 @@ Available Roles
log_and_notify_admin(logger, logging.CRITICAL, "Critical error occurred!")
**Note:** To use this role, ensure that `LOG_EMAIL_NOTIFIER` is enabled and properly configured.
**Note:** To use this role, ensure that ``ENABLE`` option of ``LOG_EMAIL_NOTIFIER`` is set to ``True``.

4. **Context Manager Role**

Expand Down
87 changes: 59 additions & 28 deletions docs/settings.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Settings
========

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.
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 Expand Up @@ -37,37 +37,68 @@ here is an example of DJANGO_LOGGING in project settings:
Here's a breakdown of the available configuration options:

- **AUTO_INITIALIZATION_ENABLE**: Accepts `bool`. Enables automatic initialization of logging configurations. Defaults to `True`.
``AUTO_INITIALIZATION_ENABLE``
------------------------------

- **INITIALIZATION_MESSAGE_ENABLE**: Accepts `bool`. Enables logging of the initialization message. Defaults to `True`.
Accepts ``bool``. Enables automatic initialization of logging configurations. Defaults to ``True``.

- **LOG_FILE_LEVELS**: Accepts a list of valid log levels (a list of `str` where each value must be one of the valid levels). Defines the log levels for file logging. Defaults to `['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']`.
``INITIALIZATION_MESSAGE_ENABLE``
---------------------------------

- **LOG_DIR**: Accepts `str` like `"path/to/logs"` or a path using functions like `os.path.join()`. Specifies the directory where log files will be stored. Defaults to `"logs"`.
Accepts ``bool``. Enables logging of the initialization message. Defaults to ``True``.

- **LOG_FILE_FORMATS**: Accepts log levels as keys and format options as values. The format option can be an `int` chosen from predefined options or a user-defined format `str`. Defines the format for log files. Defaults to `1` for all levels.
``LOG_FILE_LEVELS``
-------------------

- **Note**:See the `Available Format Options`_ below for available formats.
Accepts a list of valid log levels (a list of ``str`` where each value must be one of the valid levels). Defines the log levels for file logging. Defaults to ``['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']``.

- **LOG_CONSOLE_LEVEL**: Accepts `str` that is a valid log level. Specifies the log level for console output. Defaults to `'DEBUG'`,
``LOG_DIR``
-----------

- **LOG_CONSOLE_FORMAT**: Accepts the same options as `LOG_FILE_FORMATS`. Defines the format for console output. Defaults to `1`.
Accepts ``str`` like ``"path/to/logs"`` or a path using functions like ``os.path.join()``. Specifies the directory where log files will be stored. Defaults to ``"logs"``.

- **LOG_CONSOLE_COLORIZE**: Accepts `bool`. Determines whether to colorize console output. Defaults to `True`.
``LOG_FILE_FORMATS``
--------------------

- **LOG_DATE_FORMAT**: Accepts `str` that is a valid datetime format. Specifies the date format for log messages. Defaults to `'%Y-%m-%d %H:%M:%S'`.
Accepts log levels as keys and format options as values. The format option can be an ``int`` chosen from predefined options or a user-defined format ``str``. Defines the format for log files. Defaults to ``1`` for all levels.

- **LOG_EMAIL_NOTIFIER**: Is a dictionary where:
- **Note**:
See the `Available Format Options`_ below for available formats.

- **ENABLE**: Accepts `bool`. Determines whether the email notifier is enabled. Defaults to `False`.
``LOG_CONSOLE_LEVEL``
---------------------

Accepts ``str`` that is a valid log level. Specifies the log level for console output. Defaults to ``'DEBUG'``,

``LOG_CONSOLE_FORMAT``
----------------------

Accepts the same options as ``LOG_FILE_FORMATS``. Defines the format for console output. Defaults to ``1``.

``LOG_CONSOLE_COLORIZE``
------------------------

Accepts ``bool``. Determines whether to colorize console output. Defaults to ``True``.

``LOG_DATE_FORMAT``
-------------------

Accepts ``str`` that is a valid datetime format. Specifies the date format for log messages. Defaults to ``'%Y-%m-%d %H:%M:%S'``.

``LOG_EMAIL_NOTIFIER``
----------------------

Is a dictionary where:

- ``ENABLE``: Accepts ``bool``. Determines whether the email notifier is enabled. Defaults to ``False``.

- **NOTIFY_ERROR**: Accepts `bool`. Determines whether to notify on error logs. Defaults to `False`.
- ``NOTIFY_ERROR``: Accepts ``bool``. Determines whether to notify on error logs. Defaults to ``False``.

- **NOTIFY_CRITICAL**: Accepts `bool`. Determines whether to notify on critical logs. Defaults to `False`.
- ``NOTIFY_CRITICAL``: Accepts ``bool``. Determines whether to notify on critical logs. Defaults to ``False``.

- **LOG_FORMAT**: Accepts the same options as other log formats (`int` or `str`). Defines the format for log messages sent via email. Defaults to `1`.
- ``LOG_FORMAT``: Accepts the same options as other log formats (``int`` or ``str``). Defines the format for log messages sent via email. Defaults to ``1``.

- **USE_TEMPLATE**: Accepts `bool`. Determines whether the email includes an HTML template. Defaults to `True`.
- ``USE_TEMPLATE``: Accepts ``bool``. Determines whether the email includes an HTML template. Defaults to ``True``.


.. _available_format_options:
Expand Down Expand Up @@ -95,26 +126,26 @@ The `django_logging` package provides predefined log format options that you can
13: "%(levelname)s | [%(asctime)s] | {%(name)s} | (%(filename)s:%(lineno)d): %(message)s",
}
You can reference these formats by their corresponding integer keys in your logging configuration settings.
You can reference these formats by their corresponding **integer keys** in your logging configuration settings.


Required Email Settings
-----------------------

To use the email notifier, the following email settings must be configured in your `settings.py`:
To use the email notifier, the following email settings must be configured in your ``settings.py``:

- **`EMAIL_HOST`**: The host to use for sending emails.
- **`EMAIL_PORT`**: The port to use for the email server.
- **`EMAIL_HOST_USER`**: The username to use for the email server.
- **`EMAIL_HOST_PASSWORD`**: The password to use for the email server.
- **`EMAIL_USE_TLS`**: Whether to use a TLS (secure) connection when talking to the email server.
- **`DEFAULT_FROM_EMAIL`**: The default email address to use for sending emails.
- **`ADMIN_EMAIL`**: The email address where log notifications will be sent. This is the recipient address used by the email notifier to deliver the logs.
- ``EMAIL_HOST``: The host to use for sending emails.
- ``EMAIL_PORT``: The port to use for the email server.
- ``EMAIL_HOST_USER``: The username to use for the email server.
- ``EMAIL_HOST_PASSWORD``: The password to use for the email server.
- ``EMAIL_USE_TLS``: Whether to use a TLS (secure) connection when talking to the email server.
- ``DEFAULT_FROM_EMAIL``: The default email address to use for sending emails.
- ``ADMIN_EMAIL``: The email address where log notifications will be sent. This is the recipient address used by the email notifier to deliver the logs.

Example Email Settings
----------------------

Below is an example configuration for the email settings in your `settings.py`:
Below is an example configuration for the email settings in your ``settings.py``:

.. code-block:: python
Expand All @@ -126,4 +157,4 @@ Below is an example configuration for the email settings in your `settings.py`:
DEFAULT_FROM_EMAIL = "your-email@example.com"
ADMIN_EMAIL = "admin@example.com"
These settings ensure that the email notifier is correctly configured to send log notifications to the specified `ADMIN_EMAIL` address.
These settings ensure that the email notifier is correctly configured to send log notifications to the specified ``ADMIN_EMAIL`` address.
18 changes: 9 additions & 9 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Usage
=====

Once `django_logging` is installed and added to your `INSTALLED_APPS`, you can start using it right away. The package provides several features to customize and enhance logging in your Django project. Below is a guide on how to use the various features provided by `django_logging`.
Once ``django_logging`` is installed and added to your ``INSTALLED_APPS``, you can start using it right away. The package provides several features to customize and enhance logging in your Django project. Below is a guide on how to use the various features provided by `django_logging`.

Basic Logging Usage
-------------------
Expand All @@ -25,7 +25,7 @@ Basic Logging Usage
Request Logging Middleware
--------------------------

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:
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::
Expand All @@ -35,7 +35,7 @@ Request Logging Middleware
...
]
This middleware will log the 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 All @@ -44,7 +44,7 @@ Request Logging Middleware
Context Manager
---------------
You can use the `config_setup` context manager to temporarily apply `django_logging` configurations within a specific block of code.
You can use the ``config_setup`` context manager to temporarily apply `django_logging` configurations within a specific block of code.

Example usage:

Expand All @@ -65,7 +65,7 @@ Context Manager
foo()
Note: `AUTO_INITIALIZATION_ENABLE` must be set to `False` in the settings to use the context manager. If `AUTO_INITIALIZATION_ENABLE` is `True`, attempting to use the context manager will raise a `ValueError` with the message:
Note: ``AUTO_INITIALIZATION_ENABLE`` must be set to ``False`` in the settings to use the context manager. If it is ``True``, attempting to use the context manager will raise a ``ValueError`` with the message:

.. code-block:: text
Expand All @@ -74,7 +74,7 @@ Context Manager
Log and Notify Utility
----------------------

To send specific logs as email, use the `log_and_notify_admin` function. Ensure that the `ENABLE` option in `LOG_EMAIL_NOTIFIER` is sent to `True` in your settings:
To send specific logs as email, use the ``log_and_notify_admin`` function. Ensure that the ``ENABLE`` option in ``LOG_EMAIL_NOTIFIER`` is set to ``True`` in your settings:

.. code-block:: python
Expand All @@ -85,7 +85,7 @@ Log and Notify Utility
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:

.. code-block:: python
Expand All @@ -100,7 +100,7 @@ Log and Notify Utility
logger, logging.INFO, "This is a log message", extra={"request": request}
)
Note: To use the email notifier, `LOG_EMAIL_NOTIFIER["ENABLE"]` must be set to `True`. If it is not enabled, calling `log_and_notify_admin` will raise a `ValueError`:
Note: To use the email notifier, ``LOG_EMAIL_NOTIFIER["ENABLE"]`` must be set to ``True``. If it is not, calling ``log_and_notify_admin`` will raise a ``ValueError``:

.. code-block:: text
Expand All @@ -112,7 +112,7 @@ Log and Notify Utility
Send Logs Command
-----------------

To send the entire log directory to a specified email address, use the `send_logs` management command:
To send the entire log directory to a specified email address, use the ``send_logs`` management command:

.. code-block:: shell
Expand Down

0 comments on commit 6b6c12a

Please sign in to comment.