prairielog-handler 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) 2026 Robert Sima
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,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: prairielog-handler
3
+ Version: 0.1.0
4
+ Summary: Python logging handler for PrairieLog ingestion.
5
+ Author: PrairieLog
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://prairie-log-api.com
8
+ Project-URL: Documentation, https://prairie-log-api.com/docs.html
9
+ Project-URL: Repository, https://github.com/robertsima/log-stream-service
10
+ Project-URL: Issues, https://github.com/robertsima/log-stream-service/issues
11
+ Keywords: prairielog,logging,logs,observability
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Topic :: System :: Logging
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # PrairieLog Python Handler
21
+
22
+ Small `logging.Handler` for Python services. It batches records through `POST /api/v1/log-events/batch`, maps Python log levels to PrairieLog levels, and flushes on demand.
23
+
24
+ After registry publishing:
25
+
26
+ ```bash
27
+ pip install prairielog-handler
28
+ ```
29
+
30
+ Until then, install from this repo with `pip install ./frontend/sdk/python`.
31
+
32
+ ```python
33
+ import logging
34
+ from prairielog_handler import PrairieLogHandler
35
+
36
+ handler = PrairieLogHandler(
37
+ api_url="https://log-stream-service.onrender.com",
38
+ ingestion_token="YOUR_INGESTION_TOKEN",
39
+ logger_name="checkout-worker",
40
+ )
41
+
42
+ logging.getLogger().addHandler(handler)
43
+ logging.error("Payment failed", extra={"orderId": "ord_123"})
44
+ ```
45
+
46
+ Call `handler.flush()` before process shutdown when you cannot rely on normal logging cleanup.
@@ -0,0 +1,27 @@
1
+ # PrairieLog Python Handler
2
+
3
+ Small `logging.Handler` for Python services. It batches records through `POST /api/v1/log-events/batch`, maps Python log levels to PrairieLog levels, and flushes on demand.
4
+
5
+ After registry publishing:
6
+
7
+ ```bash
8
+ pip install prairielog-handler
9
+ ```
10
+
11
+ Until then, install from this repo with `pip install ./frontend/sdk/python`.
12
+
13
+ ```python
14
+ import logging
15
+ from prairielog_handler import PrairieLogHandler
16
+
17
+ handler = PrairieLogHandler(
18
+ api_url="https://log-stream-service.onrender.com",
19
+ ingestion_token="YOUR_INGESTION_TOKEN",
20
+ logger_name="checkout-worker",
21
+ )
22
+
23
+ logging.getLogger().addHandler(handler)
24
+ logging.error("Payment failed", extra={"orderId": "ord_123"})
25
+ ```
26
+
27
+ Call `handler.flush()` before process shutdown when you cannot rely on normal logging cleanup.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: prairielog-handler
3
+ Version: 0.1.0
4
+ Summary: Python logging handler for PrairieLog ingestion.
5
+ Author: PrairieLog
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://prairie-log-api.com
8
+ Project-URL: Documentation, https://prairie-log-api.com/docs.html
9
+ Project-URL: Repository, https://github.com/robertsima/log-stream-service
10
+ Project-URL: Issues, https://github.com/robertsima/log-stream-service/issues
11
+ Keywords: prairielog,logging,logs,observability
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Topic :: System :: Logging
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # PrairieLog Python Handler
21
+
22
+ Small `logging.Handler` for Python services. It batches records through `POST /api/v1/log-events/batch`, maps Python log levels to PrairieLog levels, and flushes on demand.
23
+
24
+ After registry publishing:
25
+
26
+ ```bash
27
+ pip install prairielog-handler
28
+ ```
29
+
30
+ Until then, install from this repo with `pip install ./frontend/sdk/python`.
31
+
32
+ ```python
33
+ import logging
34
+ from prairielog_handler import PrairieLogHandler
35
+
36
+ handler = PrairieLogHandler(
37
+ api_url="https://log-stream-service.onrender.com",
38
+ ingestion_token="YOUR_INGESTION_TOKEN",
39
+ logger_name="checkout-worker",
40
+ )
41
+
42
+ logging.getLogger().addHandler(handler)
43
+ logging.error("Payment failed", extra={"orderId": "ord_123"})
44
+ ```
45
+
46
+ Call `handler.flush()` before process shutdown when you cannot rely on normal logging cleanup.
@@ -0,0 +1,8 @@
1
+ LICENSE
2
+ README.md
3
+ prairielog_handler.py
4
+ pyproject.toml
5
+ prairielog_handler.egg-info/PKG-INFO
6
+ prairielog_handler.egg-info/SOURCES.txt
7
+ prairielog_handler.egg-info/dependency_links.txt
8
+ prairielog_handler.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ prairielog_handler
@@ -0,0 +1,97 @@
1
+ import json
2
+ import logging
3
+ import traceback
4
+ import urllib.request
5
+ import uuid
6
+ from datetime import datetime, timezone
7
+
8
+
9
+ class PrairieLogHandler(logging.Handler):
10
+ def __init__(
11
+ self,
12
+ api_url,
13
+ ingestion_token,
14
+ logger_name=None,
15
+ batch_size=50,
16
+ timeout=5,
17
+ ):
18
+ super().__init__()
19
+ self.api_url = api_url.rstrip("/")
20
+ self.ingestion_token = ingestion_token
21
+ self.logger_name = logger_name
22
+ self.batch_size = min(max(int(batch_size), 1), 100)
23
+ self.timeout = timeout
24
+ self.buffer = []
25
+
26
+ def emit(self, record):
27
+ try:
28
+ self.buffer.append(self._to_event(record))
29
+ if len(self.buffer) >= self.batch_size:
30
+ self.flush()
31
+ except Exception:
32
+ self.handleError(record)
33
+
34
+ def flush(self):
35
+ if not self.buffer:
36
+ return
37
+ batch = self.buffer
38
+ self.buffer = []
39
+ try:
40
+ self._post(batch)
41
+ except Exception:
42
+ self.buffer = batch + self.buffer
43
+ raise
44
+
45
+ def close(self):
46
+ try:
47
+ self.flush()
48
+ finally:
49
+ super().close()
50
+
51
+ def _to_event(self, record):
52
+ metadata = {
53
+ "module": record.module,
54
+ "pathname": record.pathname,
55
+ "lineno": record.lineno,
56
+ "threadName": record.threadName,
57
+ "processName": record.processName,
58
+ }
59
+ if record.exc_info:
60
+ metadata["stack"] = "".join(traceback.format_exception(*record.exc_info))
61
+ metadata["errorName"] = record.exc_info[0].__name__
62
+
63
+ return {
64
+ "id": str(uuid.uuid4()),
65
+ "level": self._level(record.levelno),
66
+ "message": record.getMessage(),
67
+ "occurredAt": datetime.fromtimestamp(record.created, timezone.utc).isoformat(),
68
+ "logger": self.logger_name or record.name,
69
+ "metadata": metadata,
70
+ }
71
+
72
+ def _post(self, batch):
73
+ body = json.dumps(batch).encode("utf-8")
74
+ request = urllib.request.Request(
75
+ f"{self.api_url}/api/v1/log-events/batch",
76
+ data=body,
77
+ method="POST",
78
+ headers={
79
+ "Content-Type": "application/json",
80
+ "X-Ingestion-Token": self.ingestion_token,
81
+ },
82
+ )
83
+ with urllib.request.urlopen(request, timeout=self.timeout) as response:
84
+ if response.status >= 400:
85
+ raise RuntimeError(f"PrairieLog request failed with {response.status}")
86
+
87
+ @staticmethod
88
+ def _level(levelno):
89
+ if levelno >= logging.ERROR:
90
+ return "ERROR"
91
+ if levelno >= logging.WARNING:
92
+ return "WARN"
93
+ if levelno >= logging.INFO:
94
+ return "INFO"
95
+ if levelno >= logging.DEBUG:
96
+ return "DEBUG"
97
+ return "TRACE"
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "prairielog-handler"
7
+ version = "0.1.0"
8
+ description = "Python logging handler for PrairieLog ingestion."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "PrairieLog" }
15
+ ]
16
+ keywords = ["prairielog", "logging", "logs", "observability"]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Topic :: System :: Logging"
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://prairie-log-api.com"
25
+ Documentation = "https://prairie-log-api.com/docs.html"
26
+ Repository = "https://github.com/robertsima/log-stream-service"
27
+ Issues = "https://github.com/robertsima/log-stream-service/issues"
28
+
29
+ [tool.setuptools]
30
+ py-modules = ["prairielog_handler"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+