json-logify 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kulbarakov Bakdoolot
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,263 @@
1
+ Metadata-Version: 2.4
2
+ Name: json-logify
3
+ Version: 0.1.0
4
+ Summary: Universal structured logging with exact JSON schema for Python frameworks
5
+ Author-email: Bakdoolot Kulbarakov <kulbarakovbh@gmail.com>
6
+ Maintainer-email: Bakdoolot Kulbarakov <kulbarakovbh@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2025 Kulbarakov Bakdoolot
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/yourusername/json-logify
30
+ Project-URL: Documentation, https://json-logify.readthedocs.io/
31
+ Project-URL: Repository, https://github.com/yourusername/json-logify
32
+ Project-URL: Issues, https://github.com/yourusername/json-logify/issues
33
+ Project-URL: Changelog, https://github.com/yourusername/json-logify/blob/main/CHANGELOG.md
34
+ Keywords: logging,structured,json,django,fastapi,flask,universal,schema,orjson,structlog
35
+ Classifier: Development Status :: 5 - Production/Stable
36
+ Classifier: Intended Audience :: Developers
37
+ Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Operating System :: OS Independent
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.8
41
+ Classifier: Programming Language :: Python :: 3.9
42
+ Classifier: Programming Language :: Python :: 3.10
43
+ Classifier: Programming Language :: Python :: 3.11
44
+ Classifier: Programming Language :: Python :: 3.12
45
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
46
+ Classifier: Topic :: System :: Logging
47
+ Classifier: Framework :: Django
48
+ Classifier: Framework :: FastAPI
49
+ Classifier: Framework :: Flask
50
+ Requires-Python: >=3.12
51
+ Description-Content-Type: text/markdown
52
+ License-File: LICENSE
53
+ Requires-Dist: structlog>=23.0.0
54
+ Requires-Dist: orjson>=3.8.0
55
+ Provides-Extra: django
56
+ Requires-Dist: django>=5.2.6; extra == "django"
57
+ Provides-Extra: fastapi
58
+ Requires-Dist: fastapi>=0.116.1; extra == "fastapi"
59
+ Requires-Dist: uvicorn>=0.35.0; extra == "fastapi"
60
+ Provides-Extra: flask
61
+ Requires-Dist: flask>=3.1.2; extra == "flask"
62
+ Provides-Extra: dev
63
+ Requires-Dist: pytest>=8.4.2; extra == "dev"
64
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
65
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
66
+ Requires-Dist: black>=23.0.0; extra == "dev"
67
+ Requires-Dist: isort>=5.12.0; extra == "dev"
68
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
69
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
70
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
71
+ Requires-Dist: bandit>=1.7.5; extra == "dev"
72
+ Provides-Extra: all
73
+ Requires-Dist: json-logify[django,fastapi,flask]; extra == "all"
74
+ Dynamic: license-file
75
+
76
+ # json-logify
77
+
78
+ Universal structured logging with exact JSON schema for Python frameworks.
79
+
80
+ [![PyPI version](https://badge.fury.io/py/json-logify.svg)](https://badge.fury.io/py/json-logify)
81
+ [![Python Support](https://img.shields.io/pypi/pyversions/json-logify.svg)](https://pypi.org/project/json-logify/)
82
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
83
+
84
+ ## Features
85
+
86
+ - <� **Exact JSON Schema**: Consistent log format across all frameworks
87
+ - � **High Performance**: Built with structlog and orjson for maximum speed
88
+ - < **Universal**: Works with Django, FastAPI, Flask, and standalone Python
89
+ - =' **Easy Setup**: One-line configuration for most use cases
90
+ - =� **Rich Context**: Request IDs, user tracking, and custom payload support
91
+ - =
92
+ **Modern Python**: Full type hints and async support
93
+
94
+ ## Quick Start
95
+
96
+ ### Installation
97
+
98
+ ```bash
99
+ # Basic installation
100
+ pip install json-logify
101
+
102
+ # For specific frameworks
103
+ pip install json-logify[django]
104
+ pip install json-logify[fastapi]
105
+ pip install json-logify[flask]
106
+
107
+ # Everything
108
+ pip install json-logify[all]
109
+ ```
110
+
111
+ ### Basic Usage
112
+
113
+ ```python
114
+ from logify import info, error
115
+
116
+ # Simple logging
117
+ info("User logged in", user_id="12345", action="login")
118
+
119
+ # Error logging with exception
120
+ try:
121
+ raise ValueError("Something went wrong")
122
+ except Exception as e:
123
+ error("Operation failed", error=e, operation="data_processing")
124
+ ```
125
+
126
+ Output:
127
+ ```json
128
+ {
129
+ "timestamp": "2025-01-15T10:30:00.123Z",
130
+ "message": "User logged in",
131
+ "level": "INFO",
132
+ "payload": {
133
+ "user_id": "12345",
134
+ "action": "login"
135
+ }
136
+ }
137
+ ```
138
+
139
+ ### Django Integration
140
+
141
+ ```python
142
+ # settings.py
143
+ from logify.django import get_logging_config
144
+
145
+ LOGGING = get_logging_config(
146
+ service_name="myapp",
147
+ json_logs=True
148
+ )
149
+
150
+ # Add middleware (optional for request tracking)
151
+ MIDDLEWARE = [
152
+ 'logify.django.LogifyMiddleware',
153
+ # ... other middleware
154
+ ]
155
+ ```
156
+
157
+ ### FastAPI Integration
158
+
159
+ ```python
160
+ from fastapi import FastAPI
161
+ from logify.fastapi import LogifyMiddleware
162
+
163
+ app = FastAPI()
164
+ app.add_middleware(LogifyMiddleware, service_name="myapi")
165
+
166
+ @app.get("/")
167
+ async def root():
168
+ from logify import info
169
+ info("API endpoint called", endpoint="/")
170
+ return {"message": "Hello World"}
171
+ ```
172
+
173
+ ### Flask Integration
174
+
175
+ ```python
176
+ from flask import Flask
177
+ from logify.flask import init_logify
178
+
179
+ app = Flask(__name__)
180
+ init_logify(app, service_name="myapp")
181
+
182
+ @app.route("/")
183
+ def hello():
184
+ from logify import info
185
+ info("Flask endpoint called", endpoint="/")
186
+ return "Hello, World!"
187
+ ```
188
+
189
+ ## Advanced Usage
190
+
191
+ ### Context Management
192
+
193
+ ```python
194
+ from logify import bind, set_request_context, clear_request_context
195
+
196
+ # Bind context to a logger
197
+ logger = bind(service="auth", module="login")
198
+ logger.info("Processing login", user_id="123")
199
+
200
+ # Set request-level context (useful in middleware)
201
+ set_request_context(request_id="req-456", user_id="123")
202
+ info("User action", action="view_profile") # Includes request context
203
+ clear_request_context()
204
+ ```
205
+
206
+ ### Performance Tracking
207
+
208
+ ```python
209
+ from logify import track_performance
210
+
211
+ @track_performance
212
+ def expensive_operation():
213
+ # Your code here
214
+ return "result"
215
+
216
+ # Automatically logs function start, completion, and duration
217
+ ```
218
+
219
+ ### Custom Configuration
220
+
221
+ ```python
222
+ from logify import configure_logging
223
+
224
+ # Configure with custom settings
225
+ configure_logging(
226
+ service_name="myapp",
227
+ level="DEBUG"
228
+ )
229
+ ```
230
+
231
+ ## Log Schema
232
+
233
+ All logs follow this exact JSON schema:
234
+
235
+ ```json
236
+ {
237
+ "timestamp": "2025-01-15T10:30:00.123Z",
238
+ "message": "Log message here",
239
+ "level": "INFO",
240
+ "error": "Error description (optional)",
241
+ "payload": {
242
+ "service": "myapp",
243
+ "request_id": "req-123",
244
+ "custom_field": "custom_value"
245
+ }
246
+ }
247
+ ```
248
+
249
+ The `error` field is optional and will only appear when logging errors or exceptions.
250
+
251
+ ## Requirements
252
+
253
+ - Python 3.8+
254
+ - structlog >= 23.0.0
255
+ - orjson >= 3.8.0
256
+
257
+ ## License
258
+
259
+ MIT License - see LICENSE file for details.
260
+
261
+ ## Contributing
262
+
263
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,187 @@
1
+ # json-logify
2
+
3
+ Universal structured logging with exact JSON schema for Python frameworks.
4
+
5
+ [![PyPI version](https://badge.fury.io/py/json-logify.svg)](https://badge.fury.io/py/json-logify)
6
+ [![Python Support](https://img.shields.io/pypi/pyversions/json-logify.svg)](https://pypi.org/project/json-logify/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ## Features
10
+
11
+ - <� **Exact JSON Schema**: Consistent log format across all frameworks
12
+ - � **High Performance**: Built with structlog and orjson for maximum speed
13
+ - < **Universal**: Works with Django, FastAPI, Flask, and standalone Python
14
+ - =' **Easy Setup**: One-line configuration for most use cases
15
+ - =� **Rich Context**: Request IDs, user tracking, and custom payload support
16
+ - =
17
  **Modern Python**: Full type hints and async support
18
+
19
+ ## Quick Start
20
+
21
+ ### Installation
22
+
23
+ ```bash
24
+ # Basic installation
25
+ pip install json-logify
26
+
27
+ # For specific frameworks
28
+ pip install json-logify[django]
29
+ pip install json-logify[fastapi]
30
+ pip install json-logify[flask]
31
+
32
+ # Everything
33
+ pip install json-logify[all]
34
+ ```
35
+
36
+ ### Basic Usage
37
+
38
+ ```python
39
+ from logify import info, error
40
+
41
+ # Simple logging
42
+ info("User logged in", user_id="12345", action="login")
43
+
44
+ # Error logging with exception
45
+ try:
46
+ raise ValueError("Something went wrong")
47
+ except Exception as e:
48
+ error("Operation failed", error=e, operation="data_processing")
49
+ ```
50
+
51
+ Output:
52
+ ```json
53
+ {
54
+ "timestamp": "2025-01-15T10:30:00.123Z",
55
+ "message": "User logged in",
56
+ "level": "INFO",
57
+ "payload": {
58
+ "user_id": "12345",
59
+ "action": "login"
60
+ }
61
+ }
62
+ ```
63
+
64
+ ### Django Integration
65
+
66
+ ```python
67
+ # settings.py
68
+ from logify.django import get_logging_config
69
+
70
+ LOGGING = get_logging_config(
71
+ service_name="myapp",
72
+ json_logs=True
73
+ )
74
+
75
+ # Add middleware (optional for request tracking)
76
+ MIDDLEWARE = [
77
+ 'logify.django.LogifyMiddleware',
78
+ # ... other middleware
79
+ ]
80
+ ```
81
+
82
+ ### FastAPI Integration
83
+
84
+ ```python
85
+ from fastapi import FastAPI
86
+ from logify.fastapi import LogifyMiddleware
87
+
88
+ app = FastAPI()
89
+ app.add_middleware(LogifyMiddleware, service_name="myapi")
90
+
91
+ @app.get("/")
92
+ async def root():
93
+ from logify import info
94
+ info("API endpoint called", endpoint="/")
95
+ return {"message": "Hello World"}
96
+ ```
97
+
98
+ ### Flask Integration
99
+
100
+ ```python
101
+ from flask import Flask
102
+ from logify.flask import init_logify
103
+
104
+ app = Flask(__name__)
105
+ init_logify(app, service_name="myapp")
106
+
107
+ @app.route("/")
108
+ def hello():
109
+ from logify import info
110
+ info("Flask endpoint called", endpoint="/")
111
+ return "Hello, World!"
112
+ ```
113
+
114
+ ## Advanced Usage
115
+
116
+ ### Context Management
117
+
118
+ ```python
119
+ from logify import bind, set_request_context, clear_request_context
120
+
121
+ # Bind context to a logger
122
+ logger = bind(service="auth", module="login")
123
+ logger.info("Processing login", user_id="123")
124
+
125
+ # Set request-level context (useful in middleware)
126
+ set_request_context(request_id="req-456", user_id="123")
127
+ info("User action", action="view_profile") # Includes request context
128
+ clear_request_context()
129
+ ```
130
+
131
+ ### Performance Tracking
132
+
133
+ ```python
134
+ from logify import track_performance
135
+
136
+ @track_performance
137
+ def expensive_operation():
138
+ # Your code here
139
+ return "result"
140
+
141
+ # Automatically logs function start, completion, and duration
142
+ ```
143
+
144
+ ### Custom Configuration
145
+
146
+ ```python
147
+ from logify import configure_logging
148
+
149
+ # Configure with custom settings
150
+ configure_logging(
151
+ service_name="myapp",
152
+ level="DEBUG"
153
+ )
154
+ ```
155
+
156
+ ## Log Schema
157
+
158
+ All logs follow this exact JSON schema:
159
+
160
+ ```json
161
+ {
162
+ "timestamp": "2025-01-15T10:30:00.123Z",
163
+ "message": "Log message here",
164
+ "level": "INFO",
165
+ "error": "Error description (optional)",
166
+ "payload": {
167
+ "service": "myapp",
168
+ "request_id": "req-123",
169
+ "custom_field": "custom_value"
170
+ }
171
+ }
172
+ ```
173
+
174
+ The `error` field is optional and will only appear when logging errors or exceptions.
175
+
176
+ ## Requirements
177
+
178
+ - Python 3.8+
179
+ - structlog >= 23.0.0
180
+ - orjson >= 3.8.0
181
+
182
+ ## License
183
+
184
+ MIT License - see LICENSE file for details.
185
+
186
+ ## Contributing
187
+
188
+ Contributions are welcome! Please feel free to submit a Pull Request.