dj-logging 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dj_logging-1.0.0.dist-info/AUTHORS.md +10 -0
- dj_logging-1.0.0.dist-info/LICENCE +21 -0
- dj_logging-1.0.0.dist-info/METADATA +331 -0
- dj_logging-1.0.0.dist-info/RECORD +78 -0
- dj_logging-1.0.0.dist-info/WHEEL +4 -0
- django_logging/__init__.py +0 -0
- django_logging/apps.py +32 -0
- django_logging/constants/__init__.py +4 -0
- django_logging/constants/ansi_colors.py +42 -0
- django_logging/constants/config_types.py +27 -0
- django_logging/constants/date_format_directives.py +22 -0
- django_logging/constants/default_settings.py +56 -0
- django_logging/constants/log_format_options.py +15 -0
- django_logging/constants/log_format_specifiers.py +18 -0
- django_logging/constants/required_email_settings.py +10 -0
- django_logging/filters/__init__.py +1 -0
- django_logging/filters/log_level_filter.py +38 -0
- django_logging/formatters/__init__.py +1 -0
- django_logging/formatters/colored_formatter.py +21 -0
- django_logging/handlers/__init__.py +1 -0
- django_logging/handlers/email_handler.py +55 -0
- django_logging/management/__init__.py +0 -0
- django_logging/management/commands/__init__.py +0 -0
- django_logging/management/commands/send_logs.py +111 -0
- django_logging/middleware/__init__.py +1 -0
- django_logging/middleware/request_middleware.py +84 -0
- django_logging/settings/__init__.py +0 -0
- django_logging/settings/checks.py +155 -0
- django_logging/settings/conf.py +219 -0
- django_logging/templates/email_notifier_template.html +48 -0
- django_logging/tests/__init__.py +0 -0
- django_logging/tests/commands/__init__.py +0 -0
- django_logging/tests/commands/test_send_logs.py +212 -0
- django_logging/tests/conftest.py +22 -0
- django_logging/tests/constants.py +2 -0
- django_logging/tests/filters/__init__.py +0 -0
- django_logging/tests/filters/test_log_level_filter.py +77 -0
- django_logging/tests/fixtures/__init__.py +14 -0
- django_logging/tests/fixtures/colored_formatter_fixture.py +16 -0
- django_logging/tests/fixtures/conf_fixture.py +46 -0
- django_logging/tests/fixtures/email_handler_fixture.py +16 -0
- django_logging/tests/fixtures/email_notifier_fixture.py +66 -0
- django_logging/tests/fixtures/email_settings_fixture.py +28 -0
- django_logging/tests/fixtures/log_and_notify_fixture.py +35 -0
- django_logging/tests/fixtures/log_record_fixture.py +43 -0
- django_logging/tests/fixtures/logger_fixture.py +23 -0
- django_logging/tests/fixtures/request_middleware_fixture.py +55 -0
- django_logging/tests/fixtures/settings_fixture.py +58 -0
- django_logging/tests/fixtures/setup_django.py +55 -0
- django_logging/tests/formatters/__init__.py +0 -0
- django_logging/tests/formatters/test_colored_formatter.py +131 -0
- django_logging/tests/handlers/__init__.py +0 -0
- django_logging/tests/handlers/test_email_handler.py +205 -0
- django_logging/tests/middleware/__init__.py +0 -0
- django_logging/tests/middleware/test_request_middleware.py +153 -0
- django_logging/tests/settings/__init__.py +0 -0
- django_logging/tests/settings/test_checks.py +287 -0
- django_logging/tests/settings/test_conf.py +182 -0
- django_logging/tests/utils/__init__.py +0 -0
- django_logging/tests/utils/test_context_manager.py +170 -0
- django_logging/tests/utils/test_email_notifier.py +127 -0
- django_logging/tests/utils/test_get_conf.py +154 -0
- django_logging/tests/utils/test_log_and_notify.py +240 -0
- django_logging/tests/utils/test_set_conf.py +226 -0
- django_logging/tests/validators/__init__.py +0 -0
- django_logging/tests/validators/test_config_validators.py +381 -0
- django_logging/tests/validators/test_email_settings_validator.py +147 -0
- django_logging/utils/__init__.py +0 -0
- django_logging/utils/console_colorizer.py +29 -0
- django_logging/utils/context_manager.py +63 -0
- django_logging/utils/get_conf.py +117 -0
- django_logging/utils/log_email_notifier/__init__.py +0 -0
- django_logging/utils/log_email_notifier/log_and_notify.py +70 -0
- django_logging/utils/log_email_notifier/notifier.py +46 -0
- django_logging/utils/set_conf.py +137 -0
- django_logging/validators/__init__.py +0 -0
- django_logging/validators/config_validators.py +239 -0
- django_logging/validators/email_settings_validator.py +40 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
## Authors
|
|
2
|
+
|
|
3
|
+
- **Aryan Niknezhad**
|
|
4
|
+
- GitHub: [ARYAN-NIKNEZHAD](https://github.com/ARYAN-NIKNEZHAD)
|
|
5
|
+
- Email: aryan513966@gmail.com
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- **Mehrshad Mirshekary**
|
|
9
|
+
- GitHub: [MEHRSHAD-MIRSHEKARY](https://github.com/MEHRSHAD-MIRSHEKARY)
|
|
10
|
+
- Email: mehrshad_mirshekary@email.com
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 django_logging
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dj-logging
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A package for logging in django applications
|
|
5
|
+
Home-page: https://github.com/ARYAN-NIKNEZHAD/django_logging
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: django_logging,django,logging
|
|
8
|
+
Author: ARYAN-NIKNEZHAD
|
|
9
|
+
Author-email: aryan513966@gmail.com
|
|
10
|
+
Requires-Python: >=3.8,<4.0
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: Framework :: Django :: 4.2
|
|
15
|
+
Classifier: Framework :: Django :: 5.0
|
|
16
|
+
Classifier: Framework :: Django :: 5.1
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
+
Requires-Dist: django (>=4.2,<5.0) ; python_version >= "3.8" and python_version < "3.10"
|
|
30
|
+
Requires-Dist: django (>=4.2,<5.3) ; python_version >= "3.10"
|
|
31
|
+
Project-URL: Documentation, https://django_logging.readthedocs.io
|
|
32
|
+
Project-URL: Issues, https://github.com/ARYAN-NIKNEZHAD/django_logging/issues
|
|
33
|
+
Project-URL: Repository, https://github.com/ARYAN-NIKNEZHAD/django_logging
|
|
34
|
+
Project-URL: Source Code, https://github.com/ARYAN-NIKNEZHAD/django_logging
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# Django Logging
|
|
38
|
+
|
|
39
|
+
The [`django_logging`](https://github.com/ARYAN-NIKNEZHAD/django_logging) is a Django package designed to extend and enhance Python’s built-in logging capabilities. By providing customizable configurations and advanced features, it offers developers a comprehensive logging solution tailored specifically for Django applications.
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+

|
|
46
|
+

|
|
47
|
+

|
|
48
|
+

|
|
49
|
+

|
|
50
|
+
[](https://codecov.io/gh/ARYAN-NIKNEZHAD/django_logging)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Project Detail
|
|
54
|
+
|
|
55
|
+
- Language: Python > 3.8
|
|
56
|
+
- Framework: Django > 4.2
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
The documentation is organized into the following sections:
|
|
62
|
+
|
|
63
|
+
- [Quick Start](#quick-start)
|
|
64
|
+
- [Usage](#usage)
|
|
65
|
+
- [Settings](#settings)
|
|
66
|
+
- [Available Format Options](#available-format-options)
|
|
67
|
+
- [Required Email Settings](#required-email-settings)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
Getting started with `django_logging` is simple. Follow these steps to get up and running quickly:
|
|
73
|
+
|
|
74
|
+
1. **Install the Package**
|
|
75
|
+
|
|
76
|
+
first, Install `django_logging` via pip:
|
|
77
|
+
|
|
78
|
+
```shell
|
|
79
|
+
$ pip install django_logging
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
2. **Add to Installed Apps**
|
|
83
|
+
|
|
84
|
+
Add `django_logging` to your `INSTALLED_APPS` in your Django settings file:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
INSTALLED_APPS = [
|
|
88
|
+
...
|
|
89
|
+
'django_logging',
|
|
90
|
+
...
|
|
91
|
+
]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
3. **Run Your Server**
|
|
96
|
+
|
|
97
|
+
Start your Django Development server to verify the installation:
|
|
98
|
+
```shell
|
|
99
|
+
python manage.py runserver
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
when the server starts, you'll see an initialization message like this in your *console*:
|
|
103
|
+
```shell
|
|
104
|
+
INFO | 'datetime' | django_logging | Logging initialized with the following configurations:
|
|
105
|
+
Log File levels: ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'].
|
|
106
|
+
Log files are being written to: logs.
|
|
107
|
+
Console output level: DEBUG.
|
|
108
|
+
Colorize console: True.
|
|
109
|
+
Log date format: %Y-%m-%d %H:%M:%S.
|
|
110
|
+
Email notifier enabled: False.
|
|
111
|
+
```
|
|
112
|
+
By default, django_logging will log each level to its own file:
|
|
113
|
+
- DEBUG : `logs/debug.log`
|
|
114
|
+
- INFO : `logs/info.log`
|
|
115
|
+
- WARNING : `logs/warning.log`
|
|
116
|
+
- ERROR : `logs/error.log`
|
|
117
|
+
- CRITICAL : `logs/critical.log`
|
|
118
|
+
|
|
119
|
+
In addition, logs will be displayed in ***colorized*** mode in the `console`, making it easier to distinguish between different log levels.
|
|
120
|
+
|
|
121
|
+
That's it! `django_logging` is ready to use. For further customization, refer to the [Settings](#settings) section
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
## Usage
|
|
125
|
+
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`.
|
|
126
|
+
|
|
127
|
+
1. **Basic Logging Usage**
|
|
128
|
+
|
|
129
|
+
At its core, `django_logging` is built on top of Python’s built-in logging module. This means you can use the standard logging module to log messages across your Django project. Here’s a basic example of logging usage:
|
|
130
|
+
```python
|
|
131
|
+
import logging
|
|
132
|
+
|
|
133
|
+
logger = logging.getLogger(__name__)
|
|
134
|
+
|
|
135
|
+
logger.debug("This is a debug message")
|
|
136
|
+
logger.info("This is an info message")
|
|
137
|
+
logger.warning("This is a warning message")
|
|
138
|
+
logger.error("This is an error message")
|
|
139
|
+
logger.critical("This is a critical message")
|
|
140
|
+
```
|
|
141
|
+
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.
|
|
142
|
+
|
|
143
|
+
2. **Request Logging Middleware**
|
|
144
|
+
|
|
145
|
+
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:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
MIDDLEWARE = [
|
|
149
|
+
...
|
|
150
|
+
'django_logging.middleware.RequestLogMiddleware',
|
|
151
|
+
...
|
|
152
|
+
]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This middleware will log th request details at info level, here is an example with default format:
|
|
156
|
+
```shell
|
|
157
|
+
INFO | 'datetime' | django_logging | Request Info: (request_path: /example-path, user: example_user,
|
|
158
|
+
IP: 192.168.1.1, user_agent: Mozilla/5.0)
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
3. **Context Manager**
|
|
163
|
+
|
|
164
|
+
You can use the `config_setup` context manager to temporarily apply `django_logging` configurations within a specific block of code.
|
|
165
|
+
Example usage:
|
|
166
|
+
```python
|
|
167
|
+
from django_logging.utils.context_manager import config_setup
|
|
168
|
+
import logging
|
|
169
|
+
|
|
170
|
+
logger = logging.getLogger(__name__)
|
|
171
|
+
|
|
172
|
+
def foo():
|
|
173
|
+
logger.info("This log will use the configuration set in the context manager!")
|
|
174
|
+
|
|
175
|
+
with config_setup():
|
|
176
|
+
""" Your logging configuration changes here"""
|
|
177
|
+
foo()
|
|
178
|
+
|
|
179
|
+
# the logging configuration will restore to what it was before, in here outside of with block
|
|
180
|
+
```
|
|
181
|
+
- 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:
|
|
182
|
+
```
|
|
183
|
+
"You must set 'AUTO_INITIALIZATION_ENABLE' to False in DJANGO_LOGGING in your settings to use the context manager."
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
4. **Log and Notify Utility**
|
|
187
|
+
|
|
188
|
+
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:
|
|
189
|
+
```python
|
|
190
|
+
from django_logging.utils.log_email_notifier.log_and_notify import log_and_notify_admin
|
|
191
|
+
import logging
|
|
192
|
+
|
|
193
|
+
logger = logging.getLogger(__name__)
|
|
194
|
+
|
|
195
|
+
log_and_notify_admin(logger, logging.INFO, "This is a log message")
|
|
196
|
+
```
|
|
197
|
+
You can also include additional request information (`ip_address` and `browser_type`) in the email by passing an `extra` dictionary:
|
|
198
|
+
```python
|
|
199
|
+
from django_logging.utils.log_email_notifier.log_and_notify import log_and_notify_admin
|
|
200
|
+
import logging
|
|
201
|
+
|
|
202
|
+
logger = logging.getLogger(__name__)
|
|
203
|
+
|
|
204
|
+
def some_view(request):
|
|
205
|
+
log_and_notify_admin(
|
|
206
|
+
logger,
|
|
207
|
+
logging.INFO,
|
|
208
|
+
"This is a log message",
|
|
209
|
+
extra={"request": request}
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- 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`:
|
|
214
|
+
```shell
|
|
215
|
+
"Email notifier is disabled. Please set the 'ENABLE' option to True in the 'LOG_EMAIL_NOTIFIER' in DJANGO_LOGGING in your settings to activate email notifications."
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Additionally, ensure that all [Required Email Settings](#required-email-settings) are configured in your Django settings file.
|
|
219
|
+
|
|
220
|
+
5. **Send Logs Command**
|
|
221
|
+
|
|
222
|
+
To send the entire log directory to a specified email address, use the `send_logs` management command:
|
|
223
|
+
```shell
|
|
224
|
+
python manage.py send_logs example@domain.com
|
|
225
|
+
```
|
|
226
|
+
This command will attach the log directory and send a zip file to the provided email address.
|
|
227
|
+
|
|
228
|
+
## Settings
|
|
229
|
+
|
|
230
|
+
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.
|
|
231
|
+
|
|
232
|
+
Example configuration:
|
|
233
|
+
```python
|
|
234
|
+
DJANGO_LOGGING = {
|
|
235
|
+
"AUTO_INITIALIZATION_ENABLE": True,
|
|
236
|
+
"INITIALIZATION_MESSAGE_ENABLE": True,
|
|
237
|
+
"LOG_FILE_LEVELS": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
|
238
|
+
"LOG_DIR": "logs",
|
|
239
|
+
"LOG_FILE_FORMATS": {
|
|
240
|
+
"DEBUG": 1,
|
|
241
|
+
"INFO": 1,
|
|
242
|
+
"WARNING": 1,
|
|
243
|
+
"ERROR": 1,
|
|
244
|
+
"CRITICAL": 1,
|
|
245
|
+
},
|
|
246
|
+
"LOG_CONSOLE_LEVEL": "DEBUG",
|
|
247
|
+
"LOG_CONSOLE_FORMAT": 1,
|
|
248
|
+
"LOG_CONSOLE_COLORIZE": True,
|
|
249
|
+
"LOG_DATE_FORMAT": "%Y-%m-%d %H:%M:%S",
|
|
250
|
+
"LOG_EMAIL_NOTIFIER": {
|
|
251
|
+
"ENABLE": False,
|
|
252
|
+
"NOTIFY_ERROR": False,
|
|
253
|
+
"NOTIFY_CRITICAL": False,
|
|
254
|
+
"LOG_FORMAT": 1,
|
|
255
|
+
"USE_TEMPLATE": True
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Here's a breakdown of the available configuration options:
|
|
261
|
+
- `AUTO_INITIALIZATION_ENABLE`: Accepts `bool`. Enables automatic initialization of logging configurations. Defaults to `True`.
|
|
262
|
+
- `INITIALIZATION_MESSAGE_ENABLE`: Accepts bool. Enables logging of the initialization message. Defaults to `True`.
|
|
263
|
+
- `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']`.
|
|
264
|
+
- `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"`.
|
|
265
|
+
- `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.
|
|
266
|
+
- **Note**: See the [Available Format Options](#available-format-options) below for available formats.
|
|
267
|
+
- `LOG_CONSOLE_LEVEL`: Accepts `str` that is a valid log level. Specifies the log level for console output. Defaults to `'DEBUG'`.
|
|
268
|
+
- `LOG_CONSOLE_FORMAT`: Accepts the same options as `LOG_FILE_FORMATS`. Defines the format for console output. Defaults to `1`.
|
|
269
|
+
- `LOG_CONSOLE_COLORIZE`: Accepts `bool`. Determines whether to colorize console output. Defaults to `True`.
|
|
270
|
+
- `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'`.
|
|
271
|
+
- `LOG_EMAIL_NOTIFIER`: Is a dictionary where:
|
|
272
|
+
- `ENABLE`: Accepts `bool`. Determines whether the email notifier is enabled. Defaults to `False`.
|
|
273
|
+
- `NOTIFY_ERROR`: Accepts `bool`. Determines whether to notify on error logs. Defaults to `False`.
|
|
274
|
+
- `NOTIFY_CRITICAL`: Accepts `bool`. Determines whether to notify on critical logs. Defaults to `False`.
|
|
275
|
+
- `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`.
|
|
276
|
+
- `USE_TEMPLATE`: Accepts `bool`. Determines whether the email includes an HTML template. Defaults to `True`.
|
|
277
|
+
|
|
278
|
+
## Available Format Options
|
|
279
|
+
|
|
280
|
+
The `django_logging` package provides predefined log format options that you can use in configuration. Below are the available format options:
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
FORMAT_OPTIONS = {
|
|
284
|
+
1: "%(levelname)s | %(asctime)s | %(module)s | %(message)s",
|
|
285
|
+
2: "%(levelname)s | %(asctime)s | %(message)s",
|
|
286
|
+
3: "%(levelname)s | %(message)s",
|
|
287
|
+
4: "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
288
|
+
5: "%(levelname)s | %(message)s | [in %(pathname)s:%(lineno)d]",
|
|
289
|
+
6: "%(asctime)s | %(levelname)s | %(message)s",
|
|
290
|
+
7: "%(levelname)s | %(asctime)s | in %(module)s: %(message)s",
|
|
291
|
+
8: "%(levelname)s | %(message)s | [%(filename)s:%(lineno)d]",
|
|
292
|
+
9: "[%(asctime)s] | %(levelname)s | in %(module)s: %(message)s",
|
|
293
|
+
10: "%(asctime)s | %(processName)s | %(name)s | %(levelname)s | %(message)s",
|
|
294
|
+
11: "%(asctime)s | %(threadName)s | %(name)s | %(levelname)s | %(message)s",
|
|
295
|
+
12: "%(levelname)s | [%(asctime)s] | (%(filename)s:%(lineno)d) | %(message)s",
|
|
296
|
+
13: "%(levelname)s | [%(asctime)s] | {%(name)s} | (%(filename)s:%(lineno)d): %(message)s",
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
You can reference these formats by their corresponding integer keys in your logging configuration settings.
|
|
301
|
+
|
|
302
|
+
## Required Email Settings
|
|
303
|
+
|
|
304
|
+
To use the email notifier, the following email settings must be configured in your `settings.py`:
|
|
305
|
+
- `EMAIL_HOST`: The host to use for sending emails.
|
|
306
|
+
- `EMAIL_PORT`: The port to use for the email server.
|
|
307
|
+
- `EMAIL_HOST_USER`: The username to use for the email server.
|
|
308
|
+
- `EMAIL_HOST_PASSWORD`: The password to use for the email server.
|
|
309
|
+
- `EMAIL_USE_TLS`: Whether to use a TLS (secure) connection when talking to the email server.
|
|
310
|
+
- `DEFAULT_FROM_EMAIL`: The default email address to use for sending emails.
|
|
311
|
+
- `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.
|
|
312
|
+
|
|
313
|
+
Example Email Settings:
|
|
314
|
+
```python
|
|
315
|
+
EMAIL_HOST = 'smtp.example.com'
|
|
316
|
+
EMAIL_PORT = 587
|
|
317
|
+
EMAIL_HOST_USER = 'your-email@example.com'
|
|
318
|
+
EMAIL_HOST_PASSWORD = 'your-password'
|
|
319
|
+
EMAIL_USE_TLS = True
|
|
320
|
+
DEFAULT_FROM_EMAIL = 'your-email@example.com'
|
|
321
|
+
ADMIN_EMAIL = 'admin@example.com'
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
These settings ensure that the email notifier is correctly configured to send log notifications to the specified `ADMIN_EMAIL` address.
|
|
325
|
+
|
|
326
|
+
## Conclusion
|
|
327
|
+
|
|
328
|
+
Thank you for using `django_logging`. We hope this package enhances your Django application's logging capabilities. For more detailed documentation, customization options, and updates, please refer to the official documentation on [Read the Docs](https://django_logging.readthedocs.io/). If you have any questions or issues, feel free to open an issue on our [GitHub repository](https://github.com/ARYAN-NIKNEZHAD/django_logging).
|
|
329
|
+
|
|
330
|
+
Happy logging!
|
|
331
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
django_logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
django_logging/apps.py,sha256=71Du0kx6GLFq7cxalFYeT3wQKbzcMUAiX8xep29S5XA,1179
|
|
3
|
+
django_logging/constants/__init__.py,sha256=O-Rctwl8KJOJkcxkz8uuYmPbZZdsnI6bPAMfFUmFU_0,238
|
|
4
|
+
django_logging/constants/ansi_colors.py,sha256=29Tmx0282lM3B3L1ojy0U6mI6y6X46lm2YnZxHKvOfg,1295
|
|
5
|
+
django_logging/constants/config_types.py,sha256=8EPl1g92JHWTtOkjkogUunuSaKUUXCJeMCWCF5fOz5Q,683
|
|
6
|
+
django_logging/constants/date_format_directives.py,sha256=tF_tbIH2NvfLfZAjSsPB69nk4Q__03d-Inm3H5rEBr4,254
|
|
7
|
+
django_logging/constants/default_settings.py,sha256=iL7h2ynPU4fWTgG5rNdNaRfDTs6mTJL7lHHDKLtiawU,1558
|
|
8
|
+
django_logging/constants/log_format_options.py,sha256=W5RO_xRccybkT1-XzWHdV1xmYdGoiK9JW8N7U5eN3Fk,918
|
|
9
|
+
django_logging/constants/log_format_specifiers.py,sha256=SJQGCsVf2u0YN5-DBWTF22k7aSxcxigKck0q_YZYY_w,294
|
|
10
|
+
django_logging/constants/required_email_settings.py,sha256=FWtY7UK4iFOsQiFKFfq_DtmcGGKME2aY-ByyImZOVAM,222
|
|
11
|
+
django_logging/filters/__init__.py,sha256=J_StGmF-RlzH0Cv08BafX-KKNzSZ7LyV1VoHEhJTxFA,50
|
|
12
|
+
django_logging/filters/log_level_filter.py,sha256=QA1RoYsRY9amMUteO_EhpG6Y2W04vCqaH0N9HE3JWpE,1203
|
|
13
|
+
django_logging/formatters/__init__.py,sha256=odNYHr1NMK1mWPYYqmVINq_mJNGlljGhItbGs0DzajM,49
|
|
14
|
+
django_logging/formatters/colored_formatter.py,sha256=y7onn8CmnCMpwaylXD9Y6JU37qOy8aCUS94qeldSZrg,776
|
|
15
|
+
django_logging/handlers/__init__.py,sha256=hgfcch6k4xZaKF0oyM_hv_9M4cN0DT21119EpTMPKPU,41
|
|
16
|
+
django_logging/handlers/email_handler.py,sha256=nAT6NA0UJ_l8mge0GqN3Tsn-0_eH5SVWvredI_x26HM,1866
|
|
17
|
+
django_logging/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
django_logging/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
django_logging/management/commands/send_logs.py,sha256=2cf0KwBRbYeH9mNXoPLa7HMO_F5xLfeZxCbnAd-cyBE,3870
|
|
20
|
+
django_logging/middleware/__init__.py,sha256=ShYaGaAeEcAs2N1s6ZMWlrrQUkrQeHF4BXWv5eGLzfs,54
|
|
21
|
+
django_logging/middleware/request_middleware.py,sha256=YeVcIgPFMmw3_eQgme3M5TXlSN1CW8zXQ7eqs3bjnS4,2717
|
|
22
|
+
django_logging/settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
|
+
django_logging/settings/checks.py,sha256=TjeZRWIQemMpE0Ih5Yjw_hYNHZ0avffjPZ5Uzvi_u4g,6136
|
|
24
|
+
django_logging/settings/conf.py,sha256=fxVXrJD6SbQ0Rv03Q8jd1lmW1yhdZxBjxXdvEvogSjo,7764
|
|
25
|
+
django_logging/templates/email_notifier_template.html,sha256=SAROoNCVhvE89taye_evBCJmvl3zeFXe5rz40FkuHCU,2994
|
|
26
|
+
django_logging/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
|
+
django_logging/tests/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
+
django_logging/tests/commands/test_send_logs.py,sha256=zKJn-raA5e2g62BjYmuwf_tEiwtakBcUFaFSTWVEAbI,8157
|
|
29
|
+
django_logging/tests/conftest.py,sha256=BJQ4uQkqaMZ-ac4QS2FQs4fAyLFvlvAa89XWk-kZ60M,560
|
|
30
|
+
django_logging/tests/constants.py,sha256=evfW-Jns06uBqdzKiD_8b9LwcEOZhm9kiyCrHhBiNKA,82
|
|
31
|
+
django_logging/tests/filters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
+
django_logging/tests/filters/test_log_level_filter.py,sha256=-dwQckqub5U9jqS0-ywicVu98Ja_0q8Nv00gHupQnW4,2665
|
|
33
|
+
django_logging/tests/fixtures/__init__.py,sha256=VA8Z75x3x7l4Uh4C1gUGKoN351uuLOaVE9jX453xCC8,670
|
|
34
|
+
django_logging/tests/fixtures/colored_formatter_fixture.py,sha256=PP8-N-iWNGZA7tlzisOiCgW0gTSi2VYz-jaHUI5GUu4,418
|
|
35
|
+
django_logging/tests/fixtures/conf_fixture.py,sha256=EzHn736Ip-jfGR4v2VWxCkPjmYwpFIExb14_j8e_BkE,1470
|
|
36
|
+
django_logging/tests/fixtures/email_handler_fixture.py,sha256=0j7na46GEJJWR8Qj7lbPfr84-5kXtxcftPfVXWfNz-E,315
|
|
37
|
+
django_logging/tests/fixtures/email_notifier_fixture.py,sha256=grGLgl9P-EgVUnBZLaI4AFXo0Cy3_3wN94fvmkUXw7o,2249
|
|
38
|
+
django_logging/tests/fixtures/email_settings_fixture.py,sha256=E4dt6KwegGZqMzYSnQmkWe_0MvSnvk4D86zD0HpjrYE,774
|
|
39
|
+
django_logging/tests/fixtures/log_and_notify_fixture.py,sha256=KOxuNtJ3nTG1D35wmBMJoDCQb1VANj_NN8aSSAstXu4,797
|
|
40
|
+
django_logging/tests/fixtures/log_record_fixture.py,sha256=Xk-XPJiX-eFH0l_5EpwVYFlZXln4NmNH8tFusLnS5CE,920
|
|
41
|
+
django_logging/tests/fixtures/logger_fixture.py,sha256=YsG_0ApmJ3Mzh-UxC9iOt9xq-yIrbO1WHeKsc0_EQv0,641
|
|
42
|
+
django_logging/tests/fixtures/request_middleware_fixture.py,sha256=TqNVkONgDw3R3pc9PTsTUR9WTNbvZ0x3tS28TSc-1q4,1356
|
|
43
|
+
django_logging/tests/fixtures/settings_fixture.py,sha256=zl2U59V5j23pbaz18-MGLbcQoZyulremo3hftQ-zesg,1806
|
|
44
|
+
django_logging/tests/fixtures/setup_django.py,sha256=lWTdw3Z26pkCZ47blAOQKs-0_5ltyhZJCvjvyxsWwaU,1888
|
|
45
|
+
django_logging/tests/formatters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
|
+
django_logging/tests/formatters/test_colored_formatter.py,sha256=8el8lwRFNlOpESVCa-MIoJsGtyMND5UzMg-aoolp84Q,4953
|
|
47
|
+
django_logging/tests/handlers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
48
|
+
django_logging/tests/handlers/test_email_handler.py,sha256=OxIYVuexHQHJOxMadbMGnX7tF7DP9NBTQRoqFADYC0I,7464
|
|
49
|
+
django_logging/tests/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
50
|
+
django_logging/tests/middleware/test_request_middleware.py,sha256=HTfrB58mNx8hKyx57aZraPqHdo3Lo146Lz5DnNOwqsQ,5381
|
|
51
|
+
django_logging/tests/settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
|
+
django_logging/tests/settings/test_checks.py,sha256=j4iGxYyBGttJ7AY4Txl2dp-B75jwF4Oz9w-p2dD2hQw,10737
|
|
53
|
+
django_logging/tests/settings/test_conf.py,sha256=6orD2mysCiONJfcZXU-TdaFVW7uDRHZy-Xwrlhx5rNQ,7074
|
|
54
|
+
django_logging/tests/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
55
|
+
django_logging/tests/utils/test_context_manager.py,sha256=4gpV6KP_dEAmF-mx0LMe-7HzG7M1rPFb-wfciD6fFl0,7393
|
|
56
|
+
django_logging/tests/utils/test_email_notifier.py,sha256=TSy2yaCRNSWBdMaD39I6m70dD9Kb_LBksAr-bBQ_l0c,4692
|
|
57
|
+
django_logging/tests/utils/test_get_conf.py,sha256=6oY00W4krqLkji4gNV4sWJp8peXKAjKmAUp2ugdesdk,6307
|
|
58
|
+
django_logging/tests/utils/test_log_and_notify.py,sha256=eH8EqPD3uttj1Jx7nkHEpoenGgUSFMbk4-8QjkHfiLM,9730
|
|
59
|
+
django_logging/tests/utils/test_set_conf.py,sha256=gRnLi-_By9VC7aJ4avx4bZO3VkiYU_HBRt-0z8s2bMI,8226
|
|
60
|
+
django_logging/tests/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
61
|
+
django_logging/tests/validators/test_config_validators.py,sha256=OpeELcyhMXBxFpZkUaG35GkgmJ2Ybea2ABXmsTlhnX4,13278
|
|
62
|
+
django_logging/tests/validators/test_email_settings_validator.py,sha256=NCD4Y9K68vosVqDvVZyWI71b8vOr1hs6GbXylyxWna8,6580
|
|
63
|
+
django_logging/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
64
|
+
django_logging/utils/console_colorizer.py,sha256=-68jAjzsbbVVeA_Gk3X0_-eQks9-eDe-SpuwaJJUNF4,1578
|
|
65
|
+
django_logging/utils/context_manager.py,sha256=Ilusmtg5Bjz4zRHYqUk4sxdhzefdPf6Xr1VePo1lgGk,2082
|
|
66
|
+
django_logging/utils/get_conf.py,sha256=iHQAz18Ob73A_jg3bN2zsx6fDHUnovma8HxONoOnca0,3979
|
|
67
|
+
django_logging/utils/log_email_notifier/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
68
|
+
django_logging/utils/log_email_notifier/log_and_notify.py,sha256=YbHxkIdNjgQB8N_vqcKfePZCFw_3KOxPOF9MgzJeEn4,2598
|
|
69
|
+
django_logging/utils/log_email_notifier/notifier.py,sha256=EBhRpfkA3NdRYsLpOCclCNfUuVpfzhTVOcBp7A7SQQU,1508
|
|
70
|
+
django_logging/utils/set_conf.py,sha256=O0ddESxhTzFa8UD3aoWAt5HekuwG-FRu2dIe7Tpq218,5208
|
|
71
|
+
django_logging/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
72
|
+
django_logging/validators/config_validators.py,sha256=9Znn3ct4cOmlJLbaKhM-MhIoh3lLn1qY73GFwDKr9C8,8683
|
|
73
|
+
django_logging/validators/email_settings_validator.py,sha256=OMHuHP97bDTLw-844tP-e10UlWRmHQAKLGQu89IB-x8,1251
|
|
74
|
+
dj_logging-1.0.0.dist-info/AUTHORS.md,sha256=UQJEI-INeq2wSS91y05pDZSTOCTAFQ9yhofJAdO9ujM,286
|
|
75
|
+
dj_logging-1.0.0.dist-info/LICENCE,sha256=fdk9QuyX4YpYn2mVlyHMxthtBCcBJTdnUtMAipNQxKU,1092
|
|
76
|
+
dj_logging-1.0.0.dist-info/METADATA,sha256=twnr_-45beKq8H7gBq5r6SgAUj4xkdu4gboY7HFvtow,14686
|
|
77
|
+
dj_logging-1.0.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
78
|
+
dj_logging-1.0.0.dist-info/RECORD,,
|
|
File without changes
|
django_logging/apps.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from django.apps import AppConfig
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DjangoLoggingConfig(AppConfig):
|
|
6
|
+
default_auto_field = "django.db.models.BigAutoField"
|
|
7
|
+
name = "django_logging"
|
|
8
|
+
verbose_name = _("Django Logging")
|
|
9
|
+
|
|
10
|
+
def ready(self) -> None:
|
|
11
|
+
"""This method is called when the Django application is ready.
|
|
12
|
+
|
|
13
|
+
The `ready` method is used to perform application-specific
|
|
14
|
+
startup tasks. In this case, it performs the following actions:
|
|
15
|
+
|
|
16
|
+
1. Imports necessary modules for checks, configuration retrieval,
|
|
17
|
+
and logging setup.
|
|
18
|
+
2. Retrieves the logging configuration from settings using `get_config`.
|
|
19
|
+
3. Sets up the logging configuration using the retrieved configs.
|
|
20
|
+
|
|
21
|
+
This ensures that the logging configuration is correctly set up
|
|
22
|
+
when the application starts.
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
from django_logging.settings import checks
|
|
26
|
+
from django_logging.utils.get_conf import get_config
|
|
27
|
+
from django_logging.utils.set_conf import set_config
|
|
28
|
+
|
|
29
|
+
conf = get_config()
|
|
30
|
+
|
|
31
|
+
# Set the logging configuration
|
|
32
|
+
set_config(**conf)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# pylint: disable=too-many-instance-attributes
|
|
5
|
+
@dataclass(frozen=True)
|
|
6
|
+
class AnsiColors:
|
|
7
|
+
BLACK: str = "\033[0;30m"
|
|
8
|
+
RED: str = "\033[0;31m"
|
|
9
|
+
GREEN: str = "\033[0;32m"
|
|
10
|
+
YELLOW: str = "\033[0;33m"
|
|
11
|
+
BLUE: str = "\033[0;34m"
|
|
12
|
+
MAGENTA: str = "\033[0;35m"
|
|
13
|
+
CYAN: str = "\033[0;36m"
|
|
14
|
+
GRAY: str = "\033[0;37m"
|
|
15
|
+
WHITE: str = "\033[0;38m"
|
|
16
|
+
RESET: str = "\033[0m"
|
|
17
|
+
BRIGHT_BLACK: str = "\033[0;90m"
|
|
18
|
+
BRIGHT_RED: str = "\033[0;91m"
|
|
19
|
+
BRIGHT_GREEN: str = "\033[0;92m"
|
|
20
|
+
BRIGHT_YELLOW: str = "\033[0;93m"
|
|
21
|
+
BRIGHT_BLUE: str = "\033[0;94m"
|
|
22
|
+
BRIGHT_MAGENTA: str = "\033[0;95m"
|
|
23
|
+
BRIGHT_CYAN: str = "\033[0;96m"
|
|
24
|
+
BRIGHT_WHITE: str = "\033[0;97m"
|
|
25
|
+
BLACK_BACKGROUND: str = "\033[40m"
|
|
26
|
+
RED_BACKGROUND: str = "\033[41m"
|
|
27
|
+
GREEN_BACKGROUND: str = "\033[42m"
|
|
28
|
+
YELLOW_BACKGROUND: str = "\033[43m"
|
|
29
|
+
BLUE_BACKGROUND: str = "\033[44m"
|
|
30
|
+
MAGENTA_BACKGROUND: str = "\033[45m"
|
|
31
|
+
CYAN_BACKGROUND: str = "\033[46m"
|
|
32
|
+
WHITE_BACKGROUND: str = "\033[47m"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Mapping log levels to ANSI colors
|
|
36
|
+
LOG_LEVEL_COLORS = {
|
|
37
|
+
"DEBUG": AnsiColors.BLUE,
|
|
38
|
+
"INFO": AnsiColors.GREEN,
|
|
39
|
+
"WARNING": AnsiColors.YELLOW,
|
|
40
|
+
"ERROR": AnsiColors.RED,
|
|
41
|
+
"CRITICAL": AnsiColors.RED_BACKGROUND,
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import List, Literal, TypedDict, Union
|
|
2
|
+
|
|
3
|
+
FormatOption = Union[int, str]
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class LogEmailNotifierType(TypedDict, total=False):
|
|
7
|
+
ENABLE: bool
|
|
8
|
+
NOTIFY_ERROR: bool
|
|
9
|
+
NOTIFY_CRITICAL: bool
|
|
10
|
+
LOG_FORMAT: FormatOption
|
|
11
|
+
USE_TEMPLATE: bool
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class LogFileFormatsType(TypedDict, total=False):
|
|
15
|
+
DEBUG: FormatOption
|
|
16
|
+
INFO: FormatOption
|
|
17
|
+
WARNING: FormatOption
|
|
18
|
+
ERROR: FormatOption
|
|
19
|
+
CRITICAL: FormatOption
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Type Aliases for other configurations
|
|
23
|
+
LogLevel = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
24
|
+
LogDir = str
|
|
25
|
+
LogLevels = List[LogLevel]
|
|
26
|
+
NotifierLogLevels = List[Literal["ERROR", "CRITICAL"]]
|
|
27
|
+
LogDateFormat = str
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import cast
|
|
4
|
+
|
|
5
|
+
from django_logging.constants.config_types import (
|
|
6
|
+
FormatOption,
|
|
7
|
+
LogDateFormat,
|
|
8
|
+
LogDir,
|
|
9
|
+
LogEmailNotifierType,
|
|
10
|
+
LogFileFormatsType,
|
|
11
|
+
LogLevel,
|
|
12
|
+
LogLevels,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class DefaultLoggingSettings:
|
|
18
|
+
log_dir: LogDir = field(default_factory=lambda: os.path.join(os.getcwd(), "logs"))
|
|
19
|
+
log_levels: LogLevels = field(
|
|
20
|
+
default_factory=lambda: ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
21
|
+
)
|
|
22
|
+
log_date_format: LogDateFormat = "%Y-%m-%d %H:%M:%S"
|
|
23
|
+
auto_initialization_enable: bool = True
|
|
24
|
+
initialization_message_enable: bool = True
|
|
25
|
+
log_file_formats: LogFileFormatsType = field(
|
|
26
|
+
default_factory=lambda: cast(
|
|
27
|
+
LogFileFormatsType,
|
|
28
|
+
{
|
|
29
|
+
"DEBUG": 1,
|
|
30
|
+
"INFO": 1,
|
|
31
|
+
"WARNING": 1,
|
|
32
|
+
"ERROR": 1,
|
|
33
|
+
"CRITICAL": 1,
|
|
34
|
+
},
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
log_email_notifier: LogEmailNotifierType = field(
|
|
39
|
+
default_factory=lambda: cast(
|
|
40
|
+
LogEmailNotifierType,
|
|
41
|
+
{
|
|
42
|
+
"ENABLE": False,
|
|
43
|
+
"NOTIFY_ERROR": False,
|
|
44
|
+
"NOTIFY_CRITICAL": False,
|
|
45
|
+
"LOG_FORMAT": 1,
|
|
46
|
+
"USE_TEMPLATE": True,
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class DefaultConsoleSettings:
|
|
54
|
+
log_console_level: LogLevel = "DEBUG"
|
|
55
|
+
log_console_format: FormatOption = 1
|
|
56
|
+
log_console_colorize: bool = True
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
FORMAT_OPTIONS = {
|
|
2
|
+
1: "%(levelname)s | %(asctime)s | %(module)s | %(message)s",
|
|
3
|
+
2: "%(levelname)s | %(asctime)s | %(message)s",
|
|
4
|
+
3: "%(levelname)s | %(message)s",
|
|
5
|
+
4: "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
6
|
+
5: "%(levelname)s | %(message)s | [in %(pathname)s:%(lineno)d]",
|
|
7
|
+
6: "%(asctime)s | %(levelname)s | %(message)s",
|
|
8
|
+
7: "%(levelname)s | %(asctime)s | in %(module)s: %(message)s",
|
|
9
|
+
8: "%(levelname)s | %(message)s | [%(filename)s:%(lineno)d]",
|
|
10
|
+
9: "[%(asctime)s] | %(levelname)s | in %(module)s: %(message)s",
|
|
11
|
+
10: "%(asctime)s | %(processName)s | %(name)s | %(levelname)s | %(message)s",
|
|
12
|
+
11: "%(asctime)s | %(threadName)s | %(name)s | %(levelname)s | %(message)s",
|
|
13
|
+
12: "%(levelname)s | [%(asctime)s] | (%(filename)s:%(lineno)d) | %(message)s",
|
|
14
|
+
13: "%(levelname)s | [%(asctime)s] | {%(name)s} | (%(filename)s:%(lineno)d): %(message)s",
|
|
15
|
+
}
|