structguru 1.7.0__tar.gz → 1.7.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.
Files changed (53) hide show
  1. {structguru-1.7.0 → structguru-1.7.2}/Cargo.lock +16 -16
  2. {structguru-1.7.0 → structguru-1.7.2}/Cargo.toml +7 -7
  3. {structguru-1.7.0 → structguru-1.7.2}/PKG-INFO +32 -3
  4. {structguru-1.7.0 → structguru-1.7.2}/README.md +31 -2
  5. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/Cargo.toml +1 -1
  6. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/src/lib.rs +25 -0
  7. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/dispatch.rs +24 -7
  8. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/filter.rs +5 -0
  9. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/lib.rs +5 -0
  10. structguru-1.7.2/crates/structguru-py/src/pipeline.rs +350 -0
  11. structguru-1.7.2/crates/structguru-py/src/submission.rs +199 -0
  12. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/template.rs +135 -5
  13. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/writer.rs +26 -13
  14. {structguru-1.7.0 → structguru-1.7.2}/pyproject.toml +14 -14
  15. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/__init__.py +1 -1
  16. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/_native_dispatch.py +10 -0
  17. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/_runtime.py +37 -71
  18. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/core.py +105 -108
  19. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/celery.py +7 -1
  20. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/flask.py +32 -30
  21. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/stdlib.py +67 -7
  22. structguru-1.7.0/crates/structguru-py/src/submission.rs +0 -105
  23. {structguru-1.7.0 → structguru-1.7.2}/LICENSE +0 -0
  24. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/src/clock.rs +0 -0
  25. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/src/filter.rs +0 -0
  26. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/src/render.rs +0 -0
  27. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/src/value.rs +0 -0
  28. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-core/src/worker.rs +0 -0
  29. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/Cargo.toml +0 -0
  30. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/conversion.rs +0 -0
  31. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/exception.rs +0 -0
  32. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/local_repr.rs +0 -0
  33. {structguru-1.7.0 → structguru-1.7.2}/crates/structguru-py/src/rendering.rs +0 -0
  34. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/_contextvars.py +0 -0
  35. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/_levels.py +0 -0
  36. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/_native_env.py +0 -0
  37. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/config.py +0 -0
  38. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/exceptions.py +0 -0
  39. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/__init__.py +0 -0
  40. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/_stdlib_env.py +0 -0
  41. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/_util.py +0 -0
  42. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/asgi.py +0 -0
  43. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/django.py +0 -0
  44. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/grpc.py +0 -0
  45. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/httpx.py +0 -0
  46. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/requests.py +0 -0
  47. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/sentry.py +0 -0
  48. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/integrations/sqlalchemy.py +0 -0
  49. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/metrics.py +0 -0
  50. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/otel.py +0 -0
  51. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/py.typed +0 -0
  52. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/redaction.py +0 -0
  53. {structguru-1.7.0 → structguru-1.7.2}/src/structguru/settings.py +0 -0
@@ -34,9 +34,9 @@ checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
34
34
 
35
35
  [[package]]
36
36
  name = "fancy-regex"
37
- version = "0.20.0"
37
+ version = "0.20.2"
38
38
  source = "registry+https://github.com/rust-lang/crates.io-index"
39
- checksum = "20ed7f62ce0ae0da1a8b93c3c7104ab7e0760a74491e097c701fff966e945390"
39
+ checksum = "0a2e16b9a584b602f1e0e5e22c30ca0906786088c27500653e432d086def8b53"
40
40
  dependencies = [
41
41
  "bit-set",
42
42
  "regex-automata",
@@ -57,9 +57,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
57
57
 
58
58
  [[package]]
59
59
  name = "itoa"
60
- version = "1.0.18"
60
+ version = "1.0.19"
61
61
  source = "registry+https://github.com/rust-lang/crates.io-index"
62
- checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
62
+ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
63
63
 
64
64
  [[package]]
65
65
  name = "libc"
@@ -174,9 +174,9 @@ dependencies = [
174
174
 
175
175
  [[package]]
176
176
  name = "regex"
177
- version = "1.13.1"
177
+ version = "1.13.2"
178
178
  source = "registry+https://github.com/rust-lang/crates.io-index"
179
- checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
179
+ checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
180
180
  dependencies = [
181
181
  "aho-corasick",
182
182
  "memchr",
@@ -186,9 +186,9 @@ dependencies = [
186
186
 
187
187
  [[package]]
188
188
  name = "regex-automata"
189
- version = "0.4.18"
189
+ version = "0.4.19"
190
190
  source = "registry+https://github.com/rust-lang/crates.io-index"
191
- checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
191
+ checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
192
192
  dependencies = [
193
193
  "aho-corasick",
194
194
  "memchr",
@@ -197,9 +197,9 @@ dependencies = [
197
197
 
198
198
  [[package]]
199
199
  name = "regex-syntax"
200
- version = "0.8.11"
200
+ version = "0.8.12"
201
201
  source = "registry+https://github.com/rust-lang/crates.io-index"
202
- checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
202
+ checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
203
203
 
204
204
  [[package]]
205
205
  name = "serde"
@@ -245,7 +245,7 @@ dependencies = [
245
245
 
246
246
  [[package]]
247
247
  name = "structguru-core"
248
- version = "1.7.0"
248
+ version = "1.7.2"
249
249
  dependencies = [
250
250
  "fancy-regex",
251
251
  "fastrand",
@@ -258,7 +258,7 @@ dependencies = [
258
258
 
259
259
  [[package]]
260
260
  name = "structguru-py"
261
- version = "1.7.0"
261
+ version = "1.7.2"
262
262
  dependencies = [
263
263
  "pyo3",
264
264
  "regex",
@@ -267,9 +267,9 @@ dependencies = [
267
267
 
268
268
  [[package]]
269
269
  name = "syn"
270
- version = "3.0.9"
270
+ version = "3.0.10"
271
271
  source = "registry+https://github.com/rust-lang/crates.io-index"
272
- checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
272
+ checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
273
273
  dependencies = [
274
274
  "proc-macro2",
275
275
  "quote",
@@ -278,9 +278,9 @@ dependencies = [
278
278
 
279
279
  [[package]]
280
280
  name = "target-lexicon"
281
- version = "0.13.5"
281
+ version = "0.13.6"
282
282
  source = "registry+https://github.com/rust-lang/crates.io-index"
283
- checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
283
+ checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
284
284
 
285
285
  [[package]]
286
286
  name = "time"
@@ -3,7 +3,7 @@ members = ["crates/structguru-core", "crates/structguru-py"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "1.7.0"
6
+ version = "1.7.2"
7
7
  edition = "2024"
8
8
  rust-version = "1.89"
9
9
  license = "MIT"
@@ -26,17 +26,17 @@ strip = true
26
26
 
27
27
  [workspace.dependencies]
28
28
  pyo3 = { version = "0.30.1" }
29
- serde = { version = "1.0" }
30
- serde_json = { version = "1.0", features = ["raw_value"] }
31
- time = { version = "0.3", features = ["macros", "formatting"] }
29
+ serde = { version = "1.0.229" }
30
+ serde_json = { version = "1.0.154", features = ["raw_value"] }
31
+ time = { version = "0.3.55", features = ["macros", "formatting"] }
32
32
  # `unicode` is on by default in the regex crate; keep it so character classes
33
33
  # match Python's `re` defaults (which are Unicode-aware on `str`).
34
- regex = { version = "1", default-features = false, features = ["std", "unicode"] }
34
+ regex = { version = "1.13.2", default-features = false, features = ["std", "unicode"] }
35
35
  # Backtracking engine for opt-in look-around/backreference redaction patterns
36
36
  # (`allow_backtracking_patterns=True`); never used unless explicitly requested.
37
- fancy-regex = { version = "0.20", default-features = false, features = ["std", "unicode"] }
37
+ fancy-regex = { version = "0.20.2", default-features = false, features = ["std", "unicode"] }
38
38
  # Only a per-thread `f64` draw is needed (sampling filter). fastrand's WyRand
39
39
  # generator has no transitive dependencies on the wheel targets, unlike rand's
40
40
  # ChaCha-based thread RNG.
41
- fastrand = { version = "2.5" }
41
+ fastrand = { version = "2.5.0" }
42
42
  structguru-core = { path = "crates/structguru-core" }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structguru
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -173,6 +173,8 @@ The stdlib bridge retains its separate `STRUCTGURU_STDLIB_*` options and explici
173
173
  ### Log levels
174
174
 
175
175
  ```python
176
+ from structguru import logger
177
+
176
178
  logger.debug("Debug message")
177
179
  logger.info("Info message")
178
180
  logger.warning("Warning message")
@@ -191,6 +193,8 @@ logger.fatal("Alias for critical")
191
193
  Arguments used in `str.format` placeholders are consumed by formatting (matching loguru behaviour). Extra kwargs that are **not** in any placeholder are forwarded as structured fields:
192
194
 
193
195
  ```python
196
+ from structguru import logger
197
+
194
198
  logger.info("User {user_id} logged in", user_id=42, ip="10.0.0.1")
195
199
  # message: "User 42 logged in"
196
200
  # ip: "10.0.0.1" (extra kwarg kept as structured field)
@@ -213,6 +217,8 @@ message whose `str()` raises, is logged raw or as a placeholder with a one-shot
213
217
  ### Bound context
214
218
 
215
219
  ```python
220
+ from structguru import logger
221
+
216
222
  log = logger.bind(request_id="abc-123", user="alice")
217
223
  log.info("Processing request") # includes request_id and user
218
224
  log.info("Request complete") # same context carried through
@@ -221,6 +227,8 @@ log.info("Request complete") # same context carried through
221
227
  ### Request-scoped context
222
228
 
223
229
  ```python
230
+ from structguru import logger
231
+
224
232
  with logger.contextualize(request_id="abc-123"):
225
233
  logger.info("Handling request") # includes request_id
226
234
  do_work() # any logging inside also gets request_id
@@ -230,6 +238,8 @@ with logger.contextualize(request_id="abc-123"):
230
238
  ### Exception logging
231
239
 
232
240
  ```python
241
+ from structguru import logger
242
+
233
243
  try:
234
244
  risky_operation()
235
245
  except Exception:
@@ -242,8 +252,10 @@ logger.opt(exception=True).error("Something went wrong")
242
252
  ### Sink management
243
253
 
244
254
  ```python
255
+ from structguru import logger
256
+
245
257
  # Add a file sink
246
- handler_id = logger.add("/var/log/app.log", level="ERROR")
258
+ handler_id = logger.add("app.log", level="ERROR")
247
259
 
248
260
  # Add a callable sink
249
261
  logger.add(lambda msg: send_to_monitoring(msg), level="CRITICAL")
@@ -290,7 +302,7 @@ been written:
290
302
  ```python
291
303
  import structguru
292
304
 
293
- logger.info("checkpoint")
305
+ structguru.logger.info("checkpoint")
294
306
  structguru.flush() # returns once the line has reached its sink
295
307
  ```
296
308
 
@@ -300,6 +312,8 @@ structguru.flush() # returns once the line has reached its sink
300
312
  (colored, human-readable development output).
301
313
 
302
314
  ```python
315
+ from structguru import update
316
+
303
317
  # JSON (production)
304
318
  update(service="myapp", format="json")
305
319
  # → {"logger":"...","level":"INFO","severity":6,"timestamp":"...","service":"myapp","message":"..."}
@@ -344,6 +358,8 @@ backtrack limit, it is redacted entirely (fail-closed) rather than emitted
344
358
  unchecked.
345
359
 
346
360
  ```python
361
+ from structguru import update
362
+
347
363
  update(
348
364
  sensitive_patterns=[r"(?<=password=)\S+"],
349
365
  allow_backtracking_patterns=True,
@@ -394,6 +410,8 @@ traceback about five times faster and matches what CPython prints under
394
410
  `PYTHONNODEBUGRANGES=1`:
395
411
 
396
412
  ```python
413
+ from structguru import update
414
+
397
415
  update(exception_carets=False)
398
416
  ```
399
417
 
@@ -516,6 +534,8 @@ Calls begun while logging is disabled are no-ops and are not counted. See the [l
516
534
  ### ASGI (FastAPI / Starlette)
517
535
 
518
536
  ```python
537
+ from fastapi import FastAPI
538
+
519
539
  from structguru.integrations.asgi import StructguruMiddleware
520
540
 
521
541
  app = FastAPI()
@@ -541,6 +561,8 @@ setup_celery_logging(propagate_context=True, context_keys=["request_id"])
541
561
  ### Flask
542
562
 
543
563
  ```python
564
+ from flask import Flask
565
+
544
566
  from structguru.integrations.flask import setup_flask_logging
545
567
 
546
568
  app = Flask(__name__)
@@ -569,6 +591,10 @@ setup_query_logging(engine, slow_threshold_ms=100, log_all=False)
569
591
  ### gRPC
570
592
 
571
593
  ```python
594
+ from concurrent import futures
595
+
596
+ import grpc
597
+
572
598
  from structguru.integrations.grpc import StructguruInterceptor
573
599
 
574
600
  server = grpc.server(
@@ -669,7 +695,10 @@ The [documentation](docs/index.md) follows [Diátaxis](https://diataxis.fr/):
669
695
  - **[Reference](docs/reference/index.md)** — API, settings and environment variables, record format, metrics, and integration details.
670
696
  - **[Explanation](docs/explanation/index.md)** — Architecture, delivery guarantees, context propagation, and redaction design.
671
697
  - **[Full-stack Example](examples/full_stack_fastapi/main.py)** — FastAPI + Celery + SQLAlchemy in action.
698
+ - **[Granian + FastAPI Example](examples/granian_fastapi/main.py)** — Launch through Granian's Python API with structured server and request logs.
672
699
  - **[Existing-loggers Example](examples/stdlib_existing_loggers/main.py)** — Configure the stdlib policy and bridge replacement from code or environment.
700
+ - **[Context-propagation Example](examples/context_propagation/main.py)** — Carry request fields through async tasks and a thread pool.
701
+ - **[Sinks and Testing Example](examples/sinks_and_testing/main.py)** — Capture, redact, and assert on rendered records with deterministic cleanup.
673
702
 
674
703
  ## Development
675
704
 
@@ -128,6 +128,8 @@ The stdlib bridge retains its separate `STRUCTGURU_STDLIB_*` options and explici
128
128
  ### Log levels
129
129
 
130
130
  ```python
131
+ from structguru import logger
132
+
131
133
  logger.debug("Debug message")
132
134
  logger.info("Info message")
133
135
  logger.warning("Warning message")
@@ -146,6 +148,8 @@ logger.fatal("Alias for critical")
146
148
  Arguments used in `str.format` placeholders are consumed by formatting (matching loguru behaviour). Extra kwargs that are **not** in any placeholder are forwarded as structured fields:
147
149
 
148
150
  ```python
151
+ from structguru import logger
152
+
149
153
  logger.info("User {user_id} logged in", user_id=42, ip="10.0.0.1")
150
154
  # message: "User 42 logged in"
151
155
  # ip: "10.0.0.1" (extra kwarg kept as structured field)
@@ -168,6 +172,8 @@ message whose `str()` raises, is logged raw or as a placeholder with a one-shot
168
172
  ### Bound context
169
173
 
170
174
  ```python
175
+ from structguru import logger
176
+
171
177
  log = logger.bind(request_id="abc-123", user="alice")
172
178
  log.info("Processing request") # includes request_id and user
173
179
  log.info("Request complete") # same context carried through
@@ -176,6 +182,8 @@ log.info("Request complete") # same context carried through
176
182
  ### Request-scoped context
177
183
 
178
184
  ```python
185
+ from structguru import logger
186
+
179
187
  with logger.contextualize(request_id="abc-123"):
180
188
  logger.info("Handling request") # includes request_id
181
189
  do_work() # any logging inside also gets request_id
@@ -185,6 +193,8 @@ with logger.contextualize(request_id="abc-123"):
185
193
  ### Exception logging
186
194
 
187
195
  ```python
196
+ from structguru import logger
197
+
188
198
  try:
189
199
  risky_operation()
190
200
  except Exception:
@@ -197,8 +207,10 @@ logger.opt(exception=True).error("Something went wrong")
197
207
  ### Sink management
198
208
 
199
209
  ```python
210
+ from structguru import logger
211
+
200
212
  # Add a file sink
201
- handler_id = logger.add("/var/log/app.log", level="ERROR")
213
+ handler_id = logger.add("app.log", level="ERROR")
202
214
 
203
215
  # Add a callable sink
204
216
  logger.add(lambda msg: send_to_monitoring(msg), level="CRITICAL")
@@ -245,7 +257,7 @@ been written:
245
257
  ```python
246
258
  import structguru
247
259
 
248
- logger.info("checkpoint")
260
+ structguru.logger.info("checkpoint")
249
261
  structguru.flush() # returns once the line has reached its sink
250
262
  ```
251
263
 
@@ -255,6 +267,8 @@ structguru.flush() # returns once the line has reached its sink
255
267
  (colored, human-readable development output).
256
268
 
257
269
  ```python
270
+ from structguru import update
271
+
258
272
  # JSON (production)
259
273
  update(service="myapp", format="json")
260
274
  # → {"logger":"...","level":"INFO","severity":6,"timestamp":"...","service":"myapp","message":"..."}
@@ -299,6 +313,8 @@ backtrack limit, it is redacted entirely (fail-closed) rather than emitted
299
313
  unchecked.
300
314
 
301
315
  ```python
316
+ from structguru import update
317
+
302
318
  update(
303
319
  sensitive_patterns=[r"(?<=password=)\S+"],
304
320
  allow_backtracking_patterns=True,
@@ -349,6 +365,8 @@ traceback about five times faster and matches what CPython prints under
349
365
  `PYTHONNODEBUGRANGES=1`:
350
366
 
351
367
  ```python
368
+ from structguru import update
369
+
352
370
  update(exception_carets=False)
353
371
  ```
354
372
 
@@ -471,6 +489,8 @@ Calls begun while logging is disabled are no-ops and are not counted. See the [l
471
489
  ### ASGI (FastAPI / Starlette)
472
490
 
473
491
  ```python
492
+ from fastapi import FastAPI
493
+
474
494
  from structguru.integrations.asgi import StructguruMiddleware
475
495
 
476
496
  app = FastAPI()
@@ -496,6 +516,8 @@ setup_celery_logging(propagate_context=True, context_keys=["request_id"])
496
516
  ### Flask
497
517
 
498
518
  ```python
519
+ from flask import Flask
520
+
499
521
  from structguru.integrations.flask import setup_flask_logging
500
522
 
501
523
  app = Flask(__name__)
@@ -524,6 +546,10 @@ setup_query_logging(engine, slow_threshold_ms=100, log_all=False)
524
546
  ### gRPC
525
547
 
526
548
  ```python
549
+ from concurrent import futures
550
+
551
+ import grpc
552
+
527
553
  from structguru.integrations.grpc import StructguruInterceptor
528
554
 
529
555
  server = grpc.server(
@@ -624,7 +650,10 @@ The [documentation](docs/index.md) follows [Diátaxis](https://diataxis.fr/):
624
650
  - **[Reference](docs/reference/index.md)** — API, settings and environment variables, record format, metrics, and integration details.
625
651
  - **[Explanation](docs/explanation/index.md)** — Architecture, delivery guarantees, context propagation, and redaction design.
626
652
  - **[Full-stack Example](examples/full_stack_fastapi/main.py)** — FastAPI + Celery + SQLAlchemy in action.
653
+ - **[Granian + FastAPI Example](examples/granian_fastapi/main.py)** — Launch through Granian's Python API with structured server and request logs.
627
654
  - **[Existing-loggers Example](examples/stdlib_existing_loggers/main.py)** — Configure the stdlib policy and bridge replacement from code or environment.
655
+ - **[Context-propagation Example](examples/context_propagation/main.py)** — Carry request fields through async tasks and a thread pool.
656
+ - **[Sinks and Testing Example](examples/sinks_and_testing/main.py)** — Capture, redact, and assert on rendered records with deterministic cleanup.
628
657
 
629
658
  ## Development
630
659
 
@@ -22,4 +22,4 @@ fancy-regex.workspace = true
22
22
  fastrand.workspace = true
23
23
 
24
24
  [target.'cfg(unix)'.dependencies]
25
- libc = "0.2"
25
+ libc = "0.2.191"
@@ -56,6 +56,19 @@ pub fn level_number(method: &str) -> Option<u8> {
56
56
  .map(|(_, number)| *number)
57
57
  }
58
58
 
59
+ /// Map a numeric stdlib level to the canonical method at or below it.
60
+ pub fn method_for_level_number(levelno: i64) -> &'static str {
61
+ match levelno {
62
+ 50.. => "critical",
63
+ 40.. => "error",
64
+ 30.. => "warning",
65
+ 20.. => "info",
66
+ 10.. => "debug",
67
+ 5.. => "trace",
68
+ _ => "debug",
69
+ }
70
+ }
71
+
59
72
  /// Normalize a structguru/loguru-style level name to the canonical field value.
60
73
  ///
61
74
  /// Unknown levels follow the current Python processor contract: uppercase the
@@ -104,6 +117,18 @@ mod tests {
104
117
  assert_eq!(level_number("notice"), None);
105
118
  }
106
119
 
120
+ #[test]
121
+ fn numeric_levels_select_their_stdlib_method_band() {
122
+ assert_eq!(method_for_level_number(-1), "debug");
123
+ assert_eq!(method_for_level_number(5), "trace");
124
+ assert_eq!(method_for_level_number(10), "debug");
125
+ assert_eq!(method_for_level_number(25), "info");
126
+ assert_eq!(method_for_level_number(35), "warning");
127
+ assert_eq!(method_for_level_number(45), "error");
128
+ assert_eq!(method_for_level_number(50), "critical");
129
+ assert_eq!(method_for_level_number(i64::MAX), "critical");
130
+ }
131
+
107
132
  #[test]
108
133
  fn level_table_lists_the_canonical_method_first_per_number() {
109
134
  let mut seen = std::collections::HashSet::new();
@@ -888,7 +888,7 @@ struct DispatcherInner {
888
888
  fork_finalizers: Mutex<Vec<Py<PyAny>>>,
889
889
  fail_spawn: AtomicBool,
890
890
  replacement_gate: AtomicU8,
891
- submissions: crate::submission::Submissions,
891
+ submissions: Arc<crate::submission::Submissions>,
892
892
  registry: Mutex<Registry>,
893
893
  /// Set while a generation is active; read lock-free on the hot path.
894
894
  active: AtomicBool,
@@ -1156,6 +1156,7 @@ impl CallableDispatcher {
1156
1156
  next_token: i64,
1157
1157
  maxsize: usize,
1158
1158
  counters: (u64, u64),
1159
+ submissions: Arc<crate::submission::Submissions>,
1159
1160
  ) -> Self {
1160
1161
  let registry = Registry {
1161
1162
  retired_snapshots: Vec::new(),
@@ -1175,7 +1176,7 @@ impl CallableDispatcher {
1175
1176
  fork_finalizers: Mutex::new(Vec::new()),
1176
1177
  fail_spawn: AtomicBool::new(false),
1177
1178
  replacement_gate: AtomicU8::new(0),
1178
- submissions: crate::submission::Submissions::default(),
1179
+ submissions,
1179
1180
  registry: Mutex::new(registry),
1180
1181
  active: AtomicBool::new(false),
1181
1182
  dropped: AtomicU64::new(dropped),
@@ -1187,16 +1188,18 @@ impl CallableDispatcher {
1187
1188
  inner.publish(py, &mut inner.lock_registry());
1188
1189
  Self { inner }
1189
1190
  }
1190
- }
1191
1191
 
1192
- impl CallableDispatcher {
1193
- pub(crate) fn begin_submission(&self) -> crate::submission::Submission<'_> {
1192
+ pub(crate) fn begin_submission(&self) -> crate::submission::Submission {
1194
1193
  self.inner.submissions.begin()
1195
1194
  }
1196
1195
  }
1197
1196
 
1198
1197
  #[pymethods]
1199
1198
  impl CallableDispatcher {
1199
+ fn _begin_submission(&self) -> crate::submission::SubmissionLease {
1200
+ crate::submission::SubmissionLease::new(self.begin_submission())
1201
+ }
1202
+
1200
1203
  fn _submission_barrier(&self) -> u64 {
1201
1204
  self.inner.submissions.barrier()
1202
1205
  }
@@ -1224,7 +1227,7 @@ impl CallableDispatcher {
1224
1227
 
1225
1228
  #[new]
1226
1229
  fn new(py: Python<'_>) -> Self {
1227
- Self::from_parts(py, Vec::new(), Vec::new(), 1, 1024, (0, 0))
1230
+ Self::from_parts(py, Vec::new(), Vec::new(), 1, 1024, (0, 0), Arc::default())
1228
1231
  }
1229
1232
 
1230
1233
  /// Register a runtime sink, starting dispatch when logging is enabled.
@@ -1483,7 +1486,13 @@ impl CallableDispatcher {
1483
1486
  /// raw stdlib delivery, bypass callable delivery. They still reach the
1484
1487
  /// native writer, but cannot recursively feed or block their own worker.
1485
1488
  #[pyo3(signature = (line, level, *, overflow))]
1486
- fn enqueue(&self, py: Python<'_>, line: String, level: i64, overflow: &str) -> PyResult<bool> {
1489
+ pub(crate) fn enqueue(
1490
+ &self,
1491
+ py: Python<'_>,
1492
+ line: String,
1493
+ level: i64,
1494
+ overflow: &str,
1495
+ ) -> PyResult<bool> {
1487
1496
  if in_callback() {
1488
1497
  return Ok(true);
1489
1498
  }
@@ -1551,6 +1560,12 @@ impl CallableDispatcher {
1551
1560
  Ok(false)
1552
1561
  }
1553
1562
 
1563
+ /// Account for a synchronous root-relay failure inside its callback scope.
1564
+ fn note_raw_error(&self, py: Python<'_>, error: Bound<'_, pyo3::exceptions::PyBaseException>) {
1565
+ self.inner
1566
+ .note_error(py, &PyErr::from_value(error.into_any()));
1567
+ }
1568
+
1554
1569
  /// Return callable dispatch queue, drop, and error metrics.
1555
1570
  fn metrics<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
1556
1571
  let registry = self.inner.lock_registry();
@@ -1602,6 +1617,7 @@ impl CallableDispatcher {
1602
1617
  Arc::from_raw(pointer)
1603
1618
  };
1604
1619
  self.inner.snapshot_readers.fetch_sub(1, Ordering::SeqCst);
1620
+ self.inner.submissions.fork_child();
1605
1621
  let child = Self::from_parts(
1606
1622
  py,
1607
1623
  snapshot
@@ -1616,6 +1632,7 @@ impl CallableDispatcher {
1616
1632
  self.inner.dropped.load(Ordering::Acquire),
1617
1633
  self.inner.errors.load(Ordering::Acquire),
1618
1634
  ),
1635
+ Arc::clone(&self.inner.submissions),
1619
1636
  );
1620
1637
  {
1621
1638
  let mut registry = child.inner.lock_registry();
@@ -69,6 +69,11 @@ impl NativeFilter {
69
69
  Ok(self.pipeline.allow(&string_to_cow(key), level))
70
70
  }
71
71
 
72
+ pub(crate) fn allow_level(&self, key: &Bound<'_, PyString>, level: i64) -> bool {
73
+ let level = u32::try_from(level.max(0)).unwrap_or(u32::MAX);
74
+ self.pipeline.allow(&string_to_cow(key), level)
75
+ }
76
+
72
77
  /// Whether any filter stage is configured.
73
78
  fn is_empty(&self) -> bool {
74
79
  self.pipeline.is_empty()
@@ -7,6 +7,7 @@ mod dispatch;
7
7
  mod exception;
8
8
  mod filter;
9
9
  mod local_repr;
10
+ mod pipeline;
10
11
  mod rendering;
11
12
  mod submission;
12
13
  mod template;
@@ -89,8 +90,12 @@ fn rust_module(module: &Bound<'_, PyModule>) -> PyResult<()> {
89
90
  module.add_function(wrap_pyfunction!(exception::_traceback_line, module)?)?;
90
91
  module.add_function(wrap_pyfunction!(template::_template_field_path, module)?)?;
91
92
  module.add_function(wrap_pyfunction!(template::_analyze_template, module)?)?;
93
+ module.add_function(wrap_pyfunction!(template::_format_simple, module)?)?;
94
+ module.add_function(wrap_pyfunction!(pipeline::submit_plain, module)?)?;
95
+ module.add_function(wrap_pyfunction!(pipeline::submit_stdlib, module)?)?;
92
96
  module.add_class::<dispatch::CallableDispatcher>()?;
93
97
  module.add_class::<dispatch::DispatchChannel>()?;
98
+ module.add_class::<submission::SubmissionLease>()?;
94
99
  module.add_function(wrap_pyfunction!(dispatch::in_callback, module)?)?;
95
100
  module.add_function(wrap_pyfunction!(dispatch::enter_callback, module)?)?;
96
101
  module.add_function(wrap_pyfunction!(dispatch::exit_callback, module)?)?;