JSONL-LOGGER 1.0.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.
- jsonl_logger-1.0.0/JSONL_LOGGER.egg-info/PKG-INFO +202 -0
- jsonl_logger-1.0.0/JSONL_LOGGER.egg-info/SOURCES.txt +9 -0
- jsonl_logger-1.0.0/JSONL_LOGGER.egg-info/dependency_links.txt +1 -0
- jsonl_logger-1.0.0/JSONL_LOGGER.egg-info/requires.txt +5 -0
- jsonl_logger-1.0.0/JSONL_LOGGER.egg-info/top_level.txt +1 -0
- jsonl_logger-1.0.0/JSONL_LOGGER.py +2625 -0
- jsonl_logger-1.0.0/LICENSE +21 -0
- jsonl_logger-1.0.0/PKG-INFO +202 -0
- jsonl_logger-1.0.0/README.md +174 -0
- jsonl_logger-1.0.0/pyproject.toml +49 -0
- jsonl_logger-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: JSONL-LOGGER
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Async queue-based structured logging with JSONL output - single file, zero dependencies beyond python-dotenv
|
|
5
|
+
Author-email: rocky <rocky@null.net>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rocky/JSONL-LOGGER
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/rocky/JSONL-LOGGER/issues
|
|
9
|
+
Project-URL: Source, https://github.com/rocky/JSONL-LOGGER
|
|
10
|
+
Keywords: logging,jsonl,structured-logging,async-logging,audit-logging
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: System :: Logging
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# JSONL-LOGGER
|
|
30
|
+
|
|
31
|
+
Async queue-based structured logging with JSONL output - single file, zero dependencies beyond python-dotenv.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install JSONL-LOGGER
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### 1. Configure Environment Variables
|
|
42
|
+
|
|
43
|
+
Create a `.env` file in your project root:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
PROJECT_DIRECTORY=/path/to/your/project
|
|
47
|
+
LOGS_LOCAL_TIMEZONE=Asia/Kolkata
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Import and Use
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from JSONL_LOGGER import log_info, log_warn, log_error, log_metric
|
|
54
|
+
|
|
55
|
+
# Info logging with structured fields
|
|
56
|
+
log_info("User logged in", user_id=123, email="user@example.com")
|
|
57
|
+
|
|
58
|
+
# Warning logging
|
|
59
|
+
log_warn("Rate limit approaching", remaining=10, reset_seconds=60)
|
|
60
|
+
|
|
61
|
+
# Error logging with error codes
|
|
62
|
+
log_error("Payment failed", error_code=500, error="insufficient_funds")
|
|
63
|
+
|
|
64
|
+
# Metrics logging (custom METR level between INFO and WARNING)
|
|
65
|
+
log_metric("api_latency_ms", 142.5, unit="ms", endpoint="/checkout", method="POST")
|
|
66
|
+
log_metric("request_count", 1000, logfile_name="orders", module_name="order_service", status="success")
|
|
67
|
+
|
|
68
|
+
# Notifications to main_logger.jsonl
|
|
69
|
+
from JSONL_LOGGER import send_notification, send_notification_async
|
|
70
|
+
|
|
71
|
+
send_notification("Application started", source_file="main.py")
|
|
72
|
+
await send_notification_async("Deployment completed", source_file="deploy.py")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
### Environment Variables
|
|
78
|
+
|
|
79
|
+
| Variable | Required | Default | Description |
|
|
80
|
+
|----------|----------|---------|-------------|
|
|
81
|
+
| `PROJECT_DIRECTORY` | Yes | - | Root directory for log storage |
|
|
82
|
+
| `LOGS_LOCAL_TIMEZONE` | Yes | - | Local timezone (e.g., `Asia/Kolkata`, `UTC`) |
|
|
83
|
+
| `LOGGER_FILE_NAME` | No | `LOGS` | Default log file name (set via env to override) |
|
|
84
|
+
| `CONSOLE_LOGGING_ENABLED` | No | `false` | Enable colored console output |
|
|
85
|
+
| `LOGGER_REGISTER_SIGNALS` | No | `false` | Register SIGINT/SIGTERM handlers for flush |
|
|
86
|
+
| `LOGGER_DAEMON_THREAD` | No | `true` | Writer thread daemon status |
|
|
87
|
+
| `LOGGER_MAX_BUFFER_SIZE` | No | `200000` | Maximum buffer entries before drop |
|
|
88
|
+
| `DEBUG_PRINT` | No | `false` | Enable debug output |
|
|
89
|
+
|
|
90
|
+
### Common Timezones
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
Asia: Asia/Kolkata, Asia/Dubai, Asia/Singapore, Asia/Tokyo
|
|
94
|
+
Europe: Europe/London, Europe/Paris, Europe/Berlin
|
|
95
|
+
Americas: America/New_York, America/Chicago, America/Los_Angeles
|
|
96
|
+
UTC: UTC
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Output
|
|
100
|
+
|
|
101
|
+
### File Structure
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
{PROJECT_DIRECTORY}/_LOGS_DIRECTORY/{YYYY_MM_DD}/LOGS/{logfile_name}.jsonl
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Example: `/path/to/logs/_LOGS_DIRECTORY/2026_04_03/LOGS/orders.jsonl`
|
|
108
|
+
|
|
109
|
+
### JSONL Format
|
|
110
|
+
|
|
111
|
+
Each log entry is a valid JSON object on a single line:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{"timestamp":"2026-04-03T05:30:00.000Z","timestamp_local":"2026-04-03T11:00:00.000+05:30","level":"INFO","logfile_name":"orders","module_name":"orders","source_file":"order_service.py","message":"User logged in","user_id":123}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Dual-Write Behavior
|
|
118
|
+
|
|
119
|
+
| Function | Writes To |
|
|
120
|
+
|----------|------------|
|
|
121
|
+
| `log_info()` | `{module}.jsonl` |
|
|
122
|
+
| `log_warn()` | `{module}.jsonl`, `{module}.warn.jsonl` |
|
|
123
|
+
| `log_error()` | `{module}.jsonl`, `{module}.errors.jsonl` |
|
|
124
|
+
| `log_metric()` | `{module}.jsonl`, `{module}.metrics.jsonl` |
|
|
125
|
+
| `send_notification()` | `main_logger.jsonl` |
|
|
126
|
+
|
|
127
|
+
## Key Features
|
|
128
|
+
|
|
129
|
+
1. **Queue-Based Async Logging** - Background thread writes to disk; API calls return immediately
|
|
130
|
+
2. **Per-Module Log Files** - Each module gets its own JSONL file for independent retention
|
|
131
|
+
3. **Dual Timestamps** - UTC for machine parsing, local time for human readability
|
|
132
|
+
4. **Retry with Exponential Backoff** - 3 attempts with 100ms/200ms/400ms delays
|
|
133
|
+
5. **Zero Data Loss** - Buffer capped at 50k entries; oldest dropped on overflow
|
|
134
|
+
6. **Signal Handlers** - Optional SIGINT/SIGTERM flush on shutdown
|
|
135
|
+
|
|
136
|
+
## Performance
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
┌───────────────────┬──────────┬──────────┬────────────┬──────────────────────────┐
|
|
140
|
+
│ Test │ Logs │ Time │ Throughput │ Status │
|
|
141
|
+
├───────────────────┼──────────┼──────────┼────────────┼──────────────────────────┤
|
|
142
|
+
│ Single-thread │ 10,000 │ 1.04 sec │ 9,643/sec │ ✅ PASS │
|
|
143
|
+
│ Multi-thread │ 100,000 │ 16.87 sec│ 5,902/sec │ ✅ PASS │
|
|
144
|
+
└───────────────────┴──────────┴──────────┴────────────┴──────────────────────────┘
|
|
145
|
+
System: Ubuntu 24.04.4 LTS | AMD Ryzen 7 5800H | Python 3.12.3
|
|
146
|
+
Tested: 10 runs average
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## API Reference
|
|
150
|
+
|
|
151
|
+
### log_info(message, logfile_name=None, module_name=None, source_file=None, **extra_fields)
|
|
152
|
+
Log an info message with optional structured fields.
|
|
153
|
+
- `message`: Log message
|
|
154
|
+
- `logfile_name`: Log file name (auto-detected if omitted)
|
|
155
|
+
- `module_name`: Source module name (auto-detected if omitted)
|
|
156
|
+
- `source_file`: Actual source filename (auto-detected if omitted)
|
|
157
|
+
- `**extra_fields`: Additional structured fields
|
|
158
|
+
|
|
159
|
+
### log_warn(message, logfile_name=None, module_name=None, source_file=None, **extra_fields)
|
|
160
|
+
Log a warning message. Writes to both main and `.warn.jsonl` files.
|
|
161
|
+
- Same parameters as `log_info`
|
|
162
|
+
|
|
163
|
+
### log_error(message, logfile_name=None, module_name=None, source_file=None, **extra_fields)
|
|
164
|
+
Log an error message. Writes to both main and `.errors.jsonl` files.
|
|
165
|
+
- Same parameters as `log_info`
|
|
166
|
+
|
|
167
|
+
### log_metric(metric_name, value, unit="", logfile_name=None, module_name=None, source_file=None, **tags)
|
|
168
|
+
Log a metric with custom METR level (between INFO and WARNING).
|
|
169
|
+
- `metric_name`: Metric identifier (e.g. "api_latency_ms")
|
|
170
|
+
- `value`: Numeric value (int or float)
|
|
171
|
+
- `unit`: Unit label (e.g. "ms", "bytes")
|
|
172
|
+
- `logfile_name`: Log file name (auto-detected if omitted)
|
|
173
|
+
- `module_name`: Source module name (auto-detected if omitted)
|
|
174
|
+
- `source_file`: Actual source filename (auto-detected if omitted)
|
|
175
|
+
- `**tags`: Additional fields for grouping/filtering
|
|
176
|
+
|
|
177
|
+
### send_notification(message, logfile_name=None, module_name=None, source_file=None)
|
|
178
|
+
Send a notification to the main_logger.jsonl file (blocking).
|
|
179
|
+
- `message`: Notification text
|
|
180
|
+
- `logfile_name`: Log file name (auto-detected if omitted)
|
|
181
|
+
- `module_name`: Source module name (auto-detected if omitted)
|
|
182
|
+
- `source_file`: Actual source filename (auto-detected if omitted)
|
|
183
|
+
|
|
184
|
+
### send_notification_async(message, logfile_name=None, module_name=None, source_file=None)
|
|
185
|
+
Send a notification to the main_logger.jsonl file (non-blocking).
|
|
186
|
+
- Same parameters as `send_notification`
|
|
187
|
+
|
|
188
|
+
### _flush_logs()
|
|
189
|
+
Manually flush all buffered logs to disk.
|
|
190
|
+
|
|
191
|
+
## Error Handling
|
|
192
|
+
|
|
193
|
+
The logger will raise `ValueError` if:
|
|
194
|
+
- `PROJECT_DIRECTORY` is not set or doesn't exist
|
|
195
|
+
- `LOGS_LOCAL_TIMEZONE` is not set
|
|
196
|
+
- Directory is not writable
|
|
197
|
+
|
|
198
|
+
Non-primitive types in extra fields will emit a stderr warning and be stringified.
|
|
199
|
+
|
|
200
|
+
## Version
|
|
201
|
+
|
|
202
|
+
Current: 1.0.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
JSONL_LOGGER
|