logcore 0.1.2__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.
logcore-0.1.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 LogForge Contributors
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.
logcore-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,433 @@
1
+ Metadata-Version: 2.4
2
+ Name: logcore
3
+ Version: 0.1.2
4
+ Summary: A production-ready structured logging library for Python
5
+ Author-email: LogForge Contributors <contributors@logforge.dev>
6
+ Maintainer-email: LogForge Contributors <contributors@logforge.dev>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2025 LogForge Contributors
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/SarkarRana/logforge
30
+ Project-URL: Bug Reports, https://github.com/SarkarRana/logforge/issues
31
+ Project-URL: Source, https://github.com/SarkarRana/logforge
32
+ Project-URL: Documentation, https://github.com/SarkarRana/logforge#readme
33
+ Keywords: logging,structured-logging,json,observability,microservices
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.8
40
+ Classifier: Programming Language :: Python :: 3.9
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
+ Classifier: Topic :: System :: Logging
46
+ Requires-Python: >=3.8
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Provides-Extra: colors
50
+ Requires-Dist: colorama>=0.4.0; extra == "colors"
51
+ Provides-Extra: dev
52
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
53
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
54
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
55
+ Requires-Dist: black>=23.0.0; extra == "dev"
56
+ Requires-Dist: isort>=5.12.0; extra == "dev"
57
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
58
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
59
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
60
+ Provides-Extra: docs
61
+ Requires-Dist: sphinx>=6.0.0; extra == "docs"
62
+ Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == "docs"
63
+ Requires-Dist: sphinx-autodoc-typehints>=1.19.0; extra == "docs"
64
+ Dynamic: license-file
65
+
66
+ # LogForge 🔥
67
+
68
+ [![PyPI version](https://badge.fury.io/py/logcore.svg)](https://badge.fury.io/py/logcore)
69
+ [![Python versions](https://img.shields.io/pypi/pyversions/logcore.svg)](https://pypi.org/project/logcore/)
70
+ [![CI](https://github.com/SarkarRana/logforge/actions/workflows/ci.yml/badge.svg)](https://github.com/SarkarRana/logforge/actions/workflows/ci.yml)
71
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/SarkarRana/logforge/blob/main/LICENSE)
72
+
73
+ **A production-ready logging library for Python**
74
+
75
+ LogForge provides a simple, structured, and extensible logging solution that works seamlessly for both small scripts and large microservices. It's designed as a drop-in alternative to Python's built-in logging with a focus on developer experience, observability, and production readiness.
76
+
77
+ ## ✨ Features
78
+
79
+ - **🚀 Simple API**: Single entrypoint with intuitive configuration
80
+ - **📊 Structured Logging**: JSON and human-readable output formats
81
+ - **🔗 Correlation IDs**: Built-in request tracing support
82
+ - **⏱️ Built-in Timing**: Context managers for performance monitoring
83
+ - **🛡️ Security**: Automatic redaction of sensitive fields
84
+ - **📁 File Rotation**: Configurable log rotation and archival
85
+ - **🎨 Colorized Output**: Beautiful console logging with colors
86
+ - **⚡ Async Support**: Safe for asyncio applications
87
+ - **🧵 Thread-safe**: Concurrent logging without issues
88
+ - **🌍 Environment Configuration**: Configure via environment variables
89
+
90
+ ## 🚀 Quick Start
91
+
92
+ ### Installation
93
+
94
+ ```bash
95
+ pip install logcore
96
+ ```
97
+
98
+ For colored output support:
99
+
100
+ ```bash
101
+ pip install logforge[colors]
102
+ ```
103
+
104
+ ### Basic Usage
105
+
106
+ ```python
107
+ from logforge import get_logger
108
+
109
+ # Create a logger
110
+ log = get_logger("myapp", level="INFO", json=True)
111
+
112
+ # Simple logging
113
+ log.info("Application started")
114
+ log.error("Something went wrong")
115
+
116
+ # Structured logging with extra fields
117
+ log.info("User login", user="alice", role="admin", success=True)
118
+
119
+ # Exception logging with automatic traceback
120
+ try:
121
+ 1 / 0
122
+ except Exception:
123
+ log.exception("Division failed")
124
+ ```
125
+
126
+ ## 📖 Documentation
127
+
128
+ ### Configuration Options
129
+
130
+ LogForge can be configured through code or environment variables:
131
+
132
+ ```python
133
+ from logforge import get_logger
134
+
135
+ log = get_logger(
136
+ name="myapp", # Logger name
137
+ level="INFO", # DEBUG, INFO, WARNING, ERROR, CRITICAL
138
+ json=True, # JSON output (False for human-readable)
139
+ file="/path/to/app.log", # Optional file logging
140
+ correlation_id="req-123", # Optional correlation ID
141
+ max_file_size=10*1024*1024, # 10MB file size limit
142
+ backup_count=5, # Keep 5 backup files
143
+ redact_fields={"password", "secret"} # Fields to redact
144
+ )
145
+ ```
146
+
147
+ ### Environment Variables
148
+
149
+ Set configuration via environment variables:
150
+
151
+ ```bash
152
+ export LOGFORGE_LEVEL=DEBUG
153
+ export LOGFORGE_JSON=true
154
+ export LOGFORGE_FILE=/var/log/app.log
155
+ export LOGFORGE_CORRELATION_ID=req-abc-123
156
+ export LOGFORGE_REDACT_FIELDS=password,token,secret
157
+ ```
158
+
159
+ ### Output Formats
160
+
161
+ #### JSON Format
162
+
163
+ ```json
164
+ {
165
+ "timestamp": "2025-01-15T10:30:45.123456",
166
+ "level": "INFO",
167
+ "logger": "myapp",
168
+ "message": "User login",
169
+ "correlation_id": "req-123",
170
+ "user": "alice",
171
+ "success": true
172
+ }
173
+ ```
174
+
175
+ #### Human-Readable Format
176
+
177
+ ```
178
+ 2025-01-15 10:30:45.123 INFO myapp [cid=req-123]: User login user=alice success=true
179
+ ```
180
+
181
+ ### Advanced Features
182
+
183
+ #### Correlation IDs for Request Tracing
184
+
185
+ ```python
186
+ from logforge import get_logger
187
+
188
+ log = get_logger("api")
189
+
190
+ # Set correlation ID for the entire request context
191
+ with log.with_correlation_id("req-abc-123"):
192
+ log.info("Processing request")
193
+ process_request()
194
+ log.info("Request completed")
195
+ ```
196
+
197
+ #### Performance Timing
198
+
199
+ ```python
200
+ # Measure execution time automatically
201
+ with log.time("database_query", level="DEBUG"):
202
+ result = expensive_database_operation()
203
+
204
+ # Outputs:
205
+ # Starting database_query
206
+ # Completed database_query duration_ms=234.56
207
+ ```
208
+
209
+ #### Exception Handling
210
+
211
+ ```python
212
+ try:
213
+ risky_operation()
214
+ except Exception as e:
215
+ log.exception("Operation failed", operation="risky_operation", user_id=123)
216
+ # Automatically includes full traceback
217
+ ```
218
+
219
+ #### Sensitive Data Redaction
220
+
221
+ ```python
222
+ # Configure fields to automatically redact
223
+ log = get_logger("secure", redact_fields={"password", "token", "ssn"})
224
+
225
+ log.info("User data", username="alice", password="secret123", role="admin")
226
+ # Output: ... username=alice password=[REDACTED] role=admin
227
+ ```
228
+
229
+ #### File Logging with Rotation
230
+
231
+ ```python
232
+ log = get_logger(
233
+ "myapp",
234
+ file="/var/log/myapp.log",
235
+ max_file_size=10 * 1024 * 1024, # 10MB
236
+ backup_count=5 # Keep 5 old files
237
+ )
238
+ ```
239
+
240
+ Files are automatically rotated:
241
+
242
+ - `myapp.log` (current)
243
+ - `myapp.log.1` (previous)
244
+ - `myapp.log.2` (older)
245
+ - etc.
246
+
247
+ ### Async Support
248
+
249
+ LogForge is fully compatible with asyncio:
250
+
251
+ ```python
252
+ import asyncio
253
+ from logforge import get_logger
254
+
255
+ async def main():
256
+ log = get_logger("async_app")
257
+
258
+ # Correlation IDs work across await boundaries
259
+ with log.with_correlation_id():
260
+ log.info("Starting async operation")
261
+ await some_async_task()
262
+ log.info("Async operation completed")
263
+
264
+ # Async timing context manager
265
+ async with log.time("async_operation"):
266
+ await another_async_task()
267
+
268
+ asyncio.run(main())
269
+ ```
270
+
271
+ ### Integration with Web Frameworks
272
+
273
+ #### Flask Example
274
+
275
+ ```python
276
+ from flask import Flask, request, g
277
+ from logforge import get_logger
278
+ import uuid
279
+
280
+ app = Flask(__name__)
281
+ log = get_logger("webapp")
282
+
283
+ @app.before_request
284
+ def before_request():
285
+ g.correlation_id = request.headers.get('X-Correlation-ID', str(uuid.uuid4()))
286
+
287
+ @app.after_request
288
+ def after_request(response):
289
+ with log.with_correlation_id(g.correlation_id):
290
+ log.info(
291
+ "Request completed",
292
+ method=request.method,
293
+ path=request.path,
294
+ status_code=response.status_code,
295
+ duration_ms=... # Add timing logic
296
+ )
297
+ return response
298
+
299
+ @app.route('/users/<user_id>')
300
+ def get_user(user_id):
301
+ with log.with_correlation_id(g.correlation_id):
302
+ log.info("Fetching user", user_id=user_id)
303
+ # ... your logic here
304
+ ```
305
+
306
+ #### FastAPI Example
307
+
308
+ ```python
309
+ from fastapi import FastAPI, Request
310
+ from logforge import get_logger
311
+ import time
312
+ import uuid
313
+
314
+ app = FastAPI()
315
+ log = get_logger("api")
316
+
317
+ @app.middleware("http")
318
+ async def logging_middleware(request: Request, call_next):
319
+ correlation_id = request.headers.get("x-correlation-id", str(uuid.uuid4()))
320
+ start_time = time.time()
321
+
322
+ with log.with_correlation_id(correlation_id):
323
+ log.info("Request started", method=request.method, url=str(request.url))
324
+
325
+ response = await call_next(request)
326
+
327
+ duration = (time.time() - start_time) * 1000
328
+ log.info(
329
+ "Request completed",
330
+ status_code=response.status_code,
331
+ duration_ms=round(duration, 2)
332
+ )
333
+
334
+ response.headers["x-correlation-id"] = correlation_id
335
+ return response
336
+ ```
337
+
338
+ ## 🆚 Comparison with Other Libraries
339
+
340
+ ### vs. Built-in `logging`
341
+
342
+ | Feature | LogForge | Built-in logging |
343
+ | ------------------ | ------------------------- | ---------------------------- |
344
+ | Setup complexity | ⭐⭐⭐⭐⭐ Single line | ⭐⭐ Complex setup |
345
+ | Structured logging | ⭐⭐⭐⭐⭐ Built-in | ⭐⭐ Manual implementation |
346
+ | JSON output | ⭐⭐⭐⭐⭐ Automatic | ⭐⭐ Custom formatter needed |
347
+ | Correlation IDs | ⭐⭐⭐⭐⭐ Built-in | ⭐ Custom context needed |
348
+ | Security | ⭐⭐⭐⭐⭐ Auto-redaction | ⭐ Manual filtering |
349
+ | Colors | ⭐⭐⭐⭐⭐ Auto-detected | ⭐⭐ Third-party needed |
350
+
351
+ ### vs. `loguru`
352
+
353
+ | Feature | LogForge | Loguru |
354
+ | ---------------- | --------------------------- | ------------------------------ |
355
+ | Production focus | ⭐⭐⭐⭐⭐ Enterprise-ready | ⭐⭐⭐⭐ Great for development |
356
+ | Correlation IDs | ⭐⭐⭐⭐⭐ Built-in context | ⭐⭐ Manual binding |
357
+ | Security | ⭐⭐⭐⭐⭐ Auto-redaction | ⭐⭐ Manual filtering |
358
+ | Async support | ⭐⭐⭐⭐⭐ Context-aware | ⭐⭐⭐ Basic support |
359
+ | Performance | ⭐⭐⭐⭐ Good | ⭐⭐⭐⭐⭐ Excellent |
360
+ | Ecosystem | ⭐⭐⭐⭐⭐ Standard logging | ⭐⭐⭐ Custom approach |
361
+
362
+ ## 🛠️ Development
363
+
364
+ ### Setup
365
+
366
+ ```bash
367
+ git clone https://github.com/logforge/logforge.git
368
+ cd logforge
369
+
370
+ # Install development dependencies
371
+ pip install -e ".[dev]"
372
+
373
+ # Install pre-commit hooks
374
+ pre-commit install
375
+ ```
376
+
377
+ ### Running Tests
378
+
379
+ ```bash
380
+ # Run all tests
381
+ pytest
382
+
383
+ # Run with coverage
384
+ pytest --cov=logforge
385
+
386
+ # Run specific test categories
387
+ pytest -m "not slow" # Skip slow tests
388
+ pytest -m integration # Run integration tests only
389
+ ```
390
+
391
+ ### Code Quality
392
+
393
+ ```bash
394
+ # Format code
395
+ black logforge tests
396
+ isort logforge tests
397
+
398
+ # Lint
399
+ flake8 logforge tests
400
+
401
+ # Type checking
402
+ mypy logforge
403
+ ```
404
+
405
+ ## 📄 License
406
+
407
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
408
+
409
+ ## 🤝 Contributing
410
+
411
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
412
+
413
+ ## 🎯 Roadmap
414
+
415
+ - [ ] **Performance Optimizations**: Async batching, lazy formatting
416
+ - [ ] **Integrations**: OpenTelemetry, Sentry, DataDog
417
+ - [ ] **Advanced Features**: Log sampling, rate limiting
418
+ - [ ] **Cloud Native**: Kubernetes-friendly output formats
419
+ - [ ] **Monitoring**: Health checks and metrics endpoints
420
+
421
+ ## 💖 Support
422
+
423
+ If you find LogForge useful, please consider:
424
+
425
+ - ⭐ Starring the repository
426
+ - 🐛 Reporting bugs and issues
427
+ - 💡 Suggesting new features
428
+ - 📖 Improving documentation
429
+ - 💻 Contributing code
430
+
431
+ ---
432
+
433
+ **Built with ❤️ for the Python community**