logxide 0.2.1__tar.gz → 0.2.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 (137) hide show
  1. logxide-0.2.2/.github/workflows/benchmark.yml +68 -0
  2. {logxide-0.2.1 → logxide-0.2.2}/CHANGELOG.md +37 -0
  3. {logxide-0.2.1 → logxide-0.2.2}/Cargo.lock +1 -1
  4. {logxide-0.2.1 → logxide-0.2.2}/Cargo.toml +1 -1
  5. {logxide-0.2.1 → logxide-0.2.2}/PKG-INFO +3 -3
  6. {logxide-0.2.1 → logxide-0.2.2}/README.md +2 -2
  7. {logxide-0.2.1 → logxide-0.2.2}/docs/benchmarks.md +2 -2
  8. {logxide-0.2.1 → logxide-0.2.2}/docs/blog-preview/part1.md +8 -8
  9. {logxide-0.2.1 → logxide-0.2.2}/docs/blog-preview/part2.md +1 -1
  10. {logxide-0.2.1 → logxide-0.2.2}/logxide/__init__.py +4 -2
  11. {logxide-0.2.1 → logxide-0.2.2}/pyproject.toml +1 -1
  12. {logxide-0.2.1 → logxide-0.2.2}/src/formatter.rs +27 -8
  13. {logxide-0.2.1 → logxide-0.2.2}/src/py_logger.rs +20 -7
  14. {logxide-0.2.1 → logxide-0.2.2}/tests/test_handler_output.py +44 -0
  15. {logxide-0.2.1 → logxide-0.2.2}/.dockerignore +0 -0
  16. {logxide-0.2.1 → logxide-0.2.2}/.github/workflows/ci.yml +0 -0
  17. {logxide-0.2.1 → logxide-0.2.2}/.github/workflows/deploy_docs.yml +0 -0
  18. {logxide-0.2.1 → logxide-0.2.2}/.github/workflows/publish.yml +0 -0
  19. {logxide-0.2.1 → logxide-0.2.2}/.gitignore +0 -0
  20. {logxide-0.2.1 → logxide-0.2.2}/.pre-commit-config.yaml +0 -0
  21. {logxide-0.2.1 → logxide-0.2.2}/CONTRIBUTING.md +0 -0
  22. {logxide-0.2.1 → logxide-0.2.2}/Dockerfile +0 -0
  23. {logxide-0.2.1 → logxide-0.2.2}/LICENSE +0 -0
  24. {logxide-0.2.1 → logxide-0.2.2}/MANIFEST.in +0 -0
  25. {logxide-0.2.1 → logxide-0.2.2}/SECURITY.md +0 -0
  26. {logxide-0.2.1 → logxide-0.2.2}/benchmark/README.md +0 -0
  27. {logxide-0.2.1 → logxide-0.2.2}/benchmark/_bench_common.py +0 -0
  28. {logxide-0.2.1 → logxide-0.2.2}/benchmark/basic_handlers_benchmark.py +0 -0
  29. {logxide-0.2.1 → logxide-0.2.2}/benchmark/compare_loggers.py +0 -0
  30. {logxide-0.2.1 → logxide-0.2.2}/benchmark/gil_benchmark.py +0 -0
  31. {logxide-0.2.1 → logxide-0.2.2}/benchmark/logger_comparison_file_io_20251230_165703.json +0 -0
  32. {logxide-0.2.1 → logxide-0.2.2}/benchmark/perf_micro.py +0 -0
  33. {logxide-0.2.1 → logxide-0.2.2}/benchmark/perf_vs_stdlib.py +0 -0
  34. {logxide-0.2.1 → logxide-0.2.2}/benchmark/real_handlers_comparison.py +0 -0
  35. {logxide-0.2.1 → logxide-0.2.2}/clippy.toml +0 -0
  36. {logxide-0.2.1 → logxide-0.2.2}/docker-compose.yml +0 -0
  37. {logxide-0.2.1 → logxide-0.2.2}/docker-run.sh +0 -0
  38. {logxide-0.2.1 → logxide-0.2.2}/docs/architecture.md +0 -0
  39. {logxide-0.2.1 → logxide-0.2.2}/docs/assets/blog/blog-part1-cover.png +0 -0
  40. {logxide-0.2.1 → logxide-0.2.2}/docs/assets/blog/blog-part2-cover.png +0 -0
  41. {logxide-0.2.1 → logxide-0.2.2}/docs/comparison-picologging.md +0 -0
  42. {logxide-0.2.1 → logxide-0.2.2}/docs/comparison-stdlib.md +0 -0
  43. {logxide-0.2.1 → logxide-0.2.2}/docs/comparison-structlog.md +0 -0
  44. {logxide-0.2.1 → logxide-0.2.2}/docs/comparison.md +0 -0
  45. {logxide-0.2.1 → logxide-0.2.2}/docs/compatibility.md +0 -0
  46. {logxide-0.2.1 → logxide-0.2.2}/docs/development.md +0 -0
  47. {logxide-0.2.1 → logxide-0.2.2}/docs/index.md +0 -0
  48. {logxide-0.2.1 → logxide-0.2.2}/docs/installation.md +0 -0
  49. {logxide-0.2.1 → logxide-0.2.2}/docs/integrations/django.md +0 -0
  50. {logxide-0.2.1 → logxide-0.2.2}/docs/integrations/fastapi.md +0 -0
  51. {logxide-0.2.1 → logxide-0.2.2}/docs/integrations/flask.md +0 -0
  52. {logxide-0.2.1 → logxide-0.2.2}/docs/integrations/index.md +0 -0
  53. {logxide-0.2.1 → logxide-0.2.2}/docs/integrations/sentry.md +0 -0
  54. {logxide-0.2.1 → logxide-0.2.2}/docs/performance-bottleneck-report-2026-07-13.md +0 -0
  55. {logxide-0.2.1 → logxide-0.2.2}/docs/reference.md +0 -0
  56. {logxide-0.2.1 → logxide-0.2.2}/docs/testing.md +0 -0
  57. {logxide-0.2.1 → logxide-0.2.2}/docs/third-party-compatibility.md +0 -0
  58. {logxide-0.2.1 → logxide-0.2.2}/docs/usage.md +0 -0
  59. {logxide-0.2.1 → logxide-0.2.2}/examples/README.md +0 -0
  60. {logxide-0.2.1 → logxide-0.2.2}/examples/basic_usage.py +0 -0
  61. {logxide-0.2.1 → logxide-0.2.2}/examples/django_integration.py +0 -0
  62. {logxide-0.2.1 → logxide-0.2.2}/examples/drop_in_replacement.py +0 -0
  63. {logxide-0.2.1 → logxide-0.2.2}/examples/fastapi_advanced.py +0 -0
  64. {logxide-0.2.1 → logxide-0.2.2}/examples/fastapi_demo.py +0 -0
  65. {logxide-0.2.1 → logxide-0.2.2}/examples/flask_integration.py +0 -0
  66. {logxide-0.2.1 → logxide-0.2.2}/examples/format_detailed.py +0 -0
  67. {logxide-0.2.1 → logxide-0.2.2}/examples/format_json.py +0 -0
  68. {logxide-0.2.1 → logxide-0.2.2}/examples/format_minimal.py +0 -0
  69. {logxide-0.2.1 → logxide-0.2.2}/examples/format_production.py +0 -0
  70. {logxide-0.2.1 → logxide-0.2.2}/examples/format_simple.py +0 -0
  71. {logxide-0.2.1 → logxide-0.2.2}/examples/format_threaded.py +0 -0
  72. {logxide-0.2.1 → logxide-0.2.2}/examples/minimal_dropin.py +0 -0
  73. {logxide-0.2.1 → logxide-0.2.2}/examples/performance_demo.py +0 -0
  74. {logxide-0.2.1 → logxide-0.2.2}/examples/sentry_integration.py +0 -0
  75. {logxide-0.2.1 → logxide-0.2.2}/examples/simple_demo.py +0 -0
  76. {logxide-0.2.1 → logxide-0.2.2}/examples/third_party_integration.py +0 -0
  77. {logxide-0.2.1 → logxide-0.2.2}/logxide/__init__.pyi +0 -0
  78. {logxide-0.2.1 → logxide-0.2.2}/logxide/compat_functions.py +0 -0
  79. {logxide-0.2.1 → logxide-0.2.2}/logxide/compat_handlers.py +0 -0
  80. {logxide-0.2.1 → logxide-0.2.2}/logxide/config.py +0 -0
  81. {logxide-0.2.1 → logxide-0.2.2}/logxide/fast_logger_wrapper.py +0 -0
  82. {logxide-0.2.1 → logxide-0.2.2}/logxide/handlers.py +0 -0
  83. {logxide-0.2.1 → logxide-0.2.2}/logxide/interceptor.py +0 -0
  84. {logxide-0.2.1 → logxide-0.2.2}/logxide/logger_wrapper.py +0 -0
  85. {logxide-0.2.1 → logxide-0.2.2}/logxide/module_system.py +0 -0
  86. {logxide-0.2.1 → logxide-0.2.2}/logxide/py.typed +0 -0
  87. {logxide-0.2.1 → logxide-0.2.2}/logxide/pytest_plugin.py +0 -0
  88. {logxide-0.2.1 → logxide-0.2.2}/logxide/sentry_integration.py +0 -0
  89. {logxide-0.2.1 → logxide-0.2.2}/logxide/testing.py +0 -0
  90. {logxide-0.2.1 → logxide-0.2.2}/mkdocs.yml +0 -0
  91. {logxide-0.2.1 → logxide-0.2.2}/pyrightconfig.json +0 -0
  92. {logxide-0.2.1 → logxide-0.2.2}/rust-toolchain.toml +0 -0
  93. {logxide-0.2.1 → logxide-0.2.2}/scripts/README.md +0 -0
  94. {logxide-0.2.1 → logxide-0.2.2}/scripts/clippy-check.sh +0 -0
  95. {logxide-0.2.1 → logxide-0.2.2}/scripts/publish.py +0 -0
  96. {logxide-0.2.1 → logxide-0.2.2}/scripts/verify_package.py +0 -0
  97. {logxide-0.2.1 → logxide-0.2.2}/social_preview.png +0 -0
  98. {logxide-0.2.1 → logxide-0.2.2}/src/config.rs +0 -0
  99. {logxide-0.2.1 → logxide-0.2.2}/src/core.rs +0 -0
  100. {logxide-0.2.1 → logxide-0.2.2}/src/fast_logger.rs +0 -0
  101. {logxide-0.2.1 → logxide-0.2.2}/src/filter.rs +0 -0
  102. {logxide-0.2.1 → logxide-0.2.2}/src/globals.rs +0 -0
  103. {logxide-0.2.1 → logxide-0.2.2}/src/handler.rs +0 -0
  104. {logxide-0.2.1 → logxide-0.2.2}/src/lib.rs +0 -0
  105. {logxide-0.2.1 → logxide-0.2.2}/src/py_handlers.rs +0 -0
  106. {logxide-0.2.1 → logxide-0.2.2}/standalone_test.py +0 -0
  107. {logxide-0.2.1 → logxide-0.2.2}/test.db +0 -0
  108. {logxide-0.2.1 → logxide-0.2.2}/tests/conftest.py +0 -0
  109. {logxide-0.2.1 → logxide-0.2.2}/tests/docker-compose.sentry.yml +0 -0
  110. {logxide-0.2.1 → logxide-0.2.2}/tests/test_basic_logging.py +0 -0
  111. {logxide-0.2.1 → logxide-0.2.2}/tests/test_caller_info_scope.py +0 -0
  112. {logxide-0.2.1 → logxide-0.2.2}/tests/test_caplog_override.py +0 -0
  113. {logxide-0.2.1 → logxide-0.2.2}/tests/test_color_formatter.py +0 -0
  114. {logxide-0.2.1 → logxide-0.2.2}/tests/test_compat_functions.py +0 -0
  115. {logxide-0.2.1 → logxide-0.2.2}/tests/test_compatibility.py +0 -0
  116. {logxide-0.2.1 → logxide-0.2.2}/tests/test_config.py +0 -0
  117. {logxide-0.2.1 → logxide-0.2.2}/tests/test_doc_codeblocks.py +0 -0
  118. {logxide-0.2.1 → logxide-0.2.2}/tests/test_examples.py +0 -0
  119. {logxide-0.2.1 → logxide-0.2.2}/tests/test_formatter_planning.py +0 -0
  120. {logxide-0.2.1 → logxide-0.2.2}/tests/test_gil_scaling.py +0 -0
  121. {logxide-0.2.1 → logxide-0.2.2}/tests/test_handler_routing.py +0 -0
  122. {logxide-0.2.1 → logxide-0.2.2}/tests/test_http_auth.py +0 -0
  123. {logxide-0.2.1 → logxide-0.2.2}/tests/test_http_handler_features.py +0 -0
  124. {logxide-0.2.1 → logxide-0.2.2}/tests/test_integration.py +0 -0
  125. {logxide-0.2.1 → logxide-0.2.2}/tests/test_integration_examples.py +0 -0
  126. {logxide-0.2.1 → logxide-0.2.2}/tests/test_integration_simple.py +0 -0
  127. {logxide-0.2.1 → logxide-0.2.2}/tests/test_interceptor.py +0 -0
  128. {logxide-0.2.1 → logxide-0.2.2}/tests/test_logxide_testing.py +0 -0
  129. {logxide-0.2.1 → logxide-0.2.2}/tests/test_native_fastpath.py +0 -0
  130. {logxide-0.2.1 → logxide-0.2.2}/tests/test_optimizations.py +0 -0
  131. {logxide-0.2.1 → logxide-0.2.2}/tests/test_overflow_flush.py +0 -0
  132. {logxide-0.2.1 → logxide-0.2.2}/tests/test_python315_compat.py +0 -0
  133. {logxide-0.2.1 → logxide-0.2.2}/tests/test_sentry_integration.py +0 -0
  134. {logxide-0.2.1 → logxide-0.2.2}/tests/test_simple.py +0 -0
  135. {logxide-0.2.1 → logxide-0.2.2}/tests/test_timed_rotation.py +0 -0
  136. {logxide-0.2.1 → logxide-0.2.2}/tmp_test_intercept.py +0 -0
  137. {logxide-0.2.1 → logxide-0.2.2}/uv.lock +0 -0
@@ -0,0 +1,68 @@
1
+ name: Benchmarks
2
+
3
+ # Reproducible, environment-matched benchmark runs on CI shared runners.
4
+ # Manual (workflow_dispatch) and a weekly schedule — NOT on every push, since
5
+ # shared-runner numbers are noisy and are meant as a documented, re-runnable
6
+ # reference rather than a per-commit gate. The clean CI venv has no sentry-sdk,
7
+ # so it inherently avoids the caller-info measurement artifact fixed in 0.2.1.
8
+
9
+ on:
10
+ workflow_dispatch:
11
+ schedule:
12
+ - cron: "0 6 * * 1" # Mondays 06:00 UTC
13
+
14
+ env:
15
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
16
+
17
+ jobs:
18
+ benchmark:
19
+ name: Benchmark (durable, sink-verified)
20
+ runs-on: ubuntu-latest
21
+ timeout-minutes: 30
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ python-version: ["3.12", "3.14"]
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ uses: actions/setup-python@v5
30
+ with:
31
+ python-version: ${{ matrix.python-version }}
32
+ - name: Set up Rust
33
+ uses: dtolnay/rust-toolchain@stable
34
+ with:
35
+ toolchain: 1.88.0
36
+ - name: Cache Rust dependencies
37
+ uses: actions/cache@v4
38
+ with:
39
+ path: |
40
+ ~/.cargo/registry
41
+ ~/.cargo/git
42
+ target
43
+ key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
44
+ - name: Install build deps
45
+ run: |
46
+ python -m pip install --upgrade uv
47
+ uv venv
48
+ uv pip install maturin
49
+ - name: Build and install (release)
50
+ env:
51
+ PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1
52
+ run: uv run maturin develop --release
53
+ - name: Confirm clean environment (no sentry-sdk)
54
+ run: |
55
+ uv run python -c "import importlib.util as u; assert u.find_spec('sentry_sdk') is None, 'sentry-sdk must NOT be installed for a clean benchmark'; import logxide; print('logxide', logxide.__version__)"
56
+ - name: Benchmark A — native FileHandler vs stdlib (perf_vs_stdlib)
57
+ run: uv run python benchmark/perf_vs_stdlib.py
58
+ - name: Benchmark B — durable cross-library sink (basic_handlers)
59
+ run: uv run python benchmark/basic_handlers_benchmark.py -n 20000
60
+ - name: Upload benchmark JSON artifacts
61
+ if: always()
62
+ uses: actions/upload-artifact@v4
63
+ with:
64
+ name: benchmark-results-py${{ matrix.python-version }}
65
+ path: |
66
+ benchmark/perf_results/
67
+ basic_handlers_benchmark_*.json
68
+ if-no-files-found: ignore
@@ -7,6 +7,43 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.2] - 2026-07-14
11
+
12
+ ### Performance
13
+ - **Skip `str()` coercion when the log message is already a `str` (M3).** The hot
14
+ path previously called `PyObject_Str` on every `logger.info(...)` even when the
15
+ message was already a `str`; it now reads the UTF-8 directly for exact-`str`
16
+ messages (guarded by an exact-type check so `str` subclasses and non-`str`
17
+ objects still coerce via `str()` exactly as before).
18
+ - **Per-second `asctime` cache (M4).** For the default date format
19
+ (`%Y-%m-%d %H:%M:%S`, no sub-second field), the formatted timestamp prefix is
20
+ cached per thread per epoch-second — byte-identical output, but avoids
21
+ re-running the chrono local-time conversion on every record. Custom `datefmt`
22
+ (which may contain `%f`) is never cached and takes the exact original path.
23
+ - Least-noisy microbench scenarios improved with no regression anywhere
24
+ (structured ~216K→~307K rec/s, `%`-args ~142K→~204K rec/s on the reference
25
+ machine; machine-specific).
26
+ - **Deferred (M2):** a Rust-native caller-frame walk was evaluated and NOT done —
27
+ low payoff now that caller-info is rarely enabled (post-0.2.1), and `PyFrame`/
28
+ `f_lineno` C-API internals differ across CPython 3.12/3.13/3.14 (correctness
29
+ risk). `populate_caller_info` is unchanged.
30
+
31
+ ### Documentation
32
+ - **Corrected the "drop-in replacement" overstatement.** README, the package
33
+ description, `logxide/__init__.py`, docs, and the blog drafts no longer claim a
34
+ flat "drop-in replacement for Python's logging"; they now say **near-drop-in for
35
+ common patterns** and link the compatibility notes documenting the differences
36
+ (flush drains/waits, no `LogRecord`/`Logger` subclassing, custom `Formatter`
37
+ subclasses fall back to a slower path, changed async-overflow default).
38
+ - Blog drafts: replaced the debunked `13.21×` / `1.9M rec/s` single-machine table
39
+ with honest sink-verified ranges and the 3.12≈3.14 parity note.
40
+
41
+ ### CI
42
+ - Added `.github/workflows/benchmark.yml` — a manual/weekly, environment-matched
43
+ (clean, no `sentry-sdk`) benchmark run across Python 3.12 and 3.14 that uploads
44
+ sink-verified results as artifacts, so the published numbers are reproducible
45
+ rather than single-machine.
46
+
10
47
  ## [0.2.1] - 2026-07-14
11
48
 
12
49
  ### Fixed
@@ -709,7 +709,7 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
709
709
 
710
710
  [[package]]
711
711
  name = "logxide"
712
- version = "0.2.1"
712
+ version = "0.2.2"
713
713
  dependencies = [
714
714
  "arc-swap",
715
715
  "chrono",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "logxide"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: logxide
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -54,7 +54,7 @@ Project-URL: Source Code, https://github.com/Indosaram/logxide
54
54
 
55
55
  **Several-fold faster than stdlib logging (roughly 5–11× on file logging, scenario- and machine-dependent), sink-verified. Powered by Rust.**
56
56
 
57
- Same stdlib API. Same `getLogger`. Same format strings. Just faster.
57
+ Familiar stdlib-style API — for common patterns, change one import and `getLogger`, format strings, and handlers work as expected. It's a **near**-drop-in, not a strict one: some advanced stdlib behaviors differ (flush now drains/waits, `LogRecord`/`Logger` can't be subclassed, custom `Formatter` subclasses fall back to a slower path). See [compatibility](docs/compatibility.md).
58
58
 
59
59
  ```python
60
60
  # Before # After
@@ -62,7 +62,7 @@ import logging from logxide import logging
62
62
 
63
63
  logging.basicConfig(level=logging.INFO)
64
64
  logger = logging.getLogger('myapp')
65
- logger.info('Hello, world!') # Same code, several-fold faster.
65
+ logger.info('Hello, world!') # Common patterns: same code, several-fold faster.
66
66
  ```
67
67
 
68
68
  [![PyPI](https://img.shields.io/pypi/v/logxide)](https://pypi.org/project/logxide/)
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Several-fold faster than stdlib logging (roughly 5–11× on file logging, scenario- and machine-dependent), sink-verified. Powered by Rust.**
4
4
 
5
- Same stdlib API. Same `getLogger`. Same format strings. Just faster.
5
+ Familiar stdlib-style API — for common patterns, change one import and `getLogger`, format strings, and handlers work as expected. It's a **near**-drop-in, not a strict one: some advanced stdlib behaviors differ (flush now drains/waits, `LogRecord`/`Logger` can't be subclassed, custom `Formatter` subclasses fall back to a slower path). See [compatibility](docs/compatibility.md).
6
6
 
7
7
  ```python
8
8
  # Before # After
@@ -10,7 +10,7 @@ import logging from logxide import logging
10
10
 
11
11
  logging.basicConfig(level=logging.INFO)
12
12
  logger = logging.getLogger('myapp')
13
- logger.info('Hello, world!') # Same code, several-fold faster.
13
+ logger.info('Hello, world!') # Common patterns: same code, several-fold faster.
14
14
  ```
15
15
 
16
16
  [![PyPI](https://img.shields.io/pypi/v/logxide)](https://pypi.org/project/logxide/)
@@ -243,7 +243,7 @@ LogXide is faster on both versions. There is no intrinsic Python 3.14 regression
243
243
  **Choose LogXide when:**
244
244
  - You need maximum performance in production
245
245
  - Your application does significant logging to files
246
- - You want a drop-in replacement with better performance
246
+ - You want a near-drop-in (common patterns) with better performance
247
247
  - You value consistent performance across scenarios
248
248
 
249
249
  **Choose Picologging when:**
@@ -302,7 +302,7 @@ python benchmark/compare_loggers.py
302
302
 
303
303
  1. **Strong file-I/O performance**: Against stdlib in the subprocess-isolated, synchronous-`FileHandler` scenario, LogXide is substantially faster. The corrected, sink-verified harness puts LogXide at ~6–11× stdlib on the durable file path and ~8–14× on rotating, plus ~5× on the async stream sink when it fully drains; exact multipliers are machine- and scenario-specific, and Python 3.12 and 3.14 are at parity.
304
304
  2. **Real-World Testing**: Benchmarks based on actual file operations, not synthetic tests
305
- 3. **Drop-in Replacement**: No code changes required for common patterns
305
+ 3. **Near-drop-in**: minimal/no code changes for common patterns (some advanced stdlib scenarios differ — see [compatibility](compatibility.md))
306
306
  4. **Native Performance**: Rust's efficiency provides measurable benefits
307
307
 
308
308
  ### Performance Summary Table (durable, sink-verified)
@@ -6,7 +6,7 @@ Last month I was setting up Sentry for a FastAPI project. I'd done this fourteen
6
6
 
7
7
  Forty minutes later I had three packages installed, a 25-line config file, and Sentry breadcrumbs that still refused to appear. I stared at my screen and thought: this is stupid. This should take thirty seconds.
8
8
 
9
- That's why I built LogXide. It's a drop-in replacement for Python's stdlib logging, written in Rust. Same API. Same `getLogger`, same format strings. But up to 13× faster, and Sentry and OTLP just work. No handlers to configure. No JSON files to juggle.
9
+ That's why I built LogXide. It's a high-performance, largely stdlib-compatible logging library written in Rust — a near-drop-in for common patterns. Same `getLogger`, same format strings. Several-fold faster, and Sentry and OTLP just work. No handlers to configure. No JSON files to juggle. (It's not a strict drop-in — see the compatibility notes for the advanced patterns that differ.)
10
10
 
11
11
  ## The One-Line Migration
12
12
 
@@ -165,15 +165,15 @@ Sentry and OTLP work together. An error can trigger a Sentry event and ship to y
165
165
 
166
166
  ## Performance
167
167
 
168
- LogXide is up to 13× faster than stdlib logging:
168
+ LogXide is several-fold faster than stdlib logging — roughly 5–11× on file logging depending on the scenario. The numbers are sink-verified (records the sink actually confirmed after flush, not just enqueued), machine-specific, and comparable across Python 3.12 and 3.14, so treat them as ranges rather than a single figure:
169
169
 
170
- | Scenario | LogXide | stdlib | Speedup |
171
- | :--------- | --------: | ------: | --------: |
172
- | Simple msg | 1.92M ops/s | 146K ops/s | **13.21×** |
173
- | Structured | 1.61M ops/s | 144K ops/s | **11.17×** |
174
- | with `%s` args | 977K ops/s | 144K ops/s | **6.77×** |
170
+ | Scenario | vs stdlib (sink-verified) |
171
+ | :--------- | :------------------------ |
172
+ | Simple msg | ~7–9× |
173
+ | Structured | ~7–9× |
174
+ | with `%s` args | ~5–6× |
175
175
 
176
- It's also ~3× faster than Microsoft's picologging on the same Python version, which is written in C. Picologging exists and is good. LogXide is faster, runs on Python 3.13+, and has Sentry/OTLP built in.
176
+ It's also faster than Microsoft's picologging (written in C) on the same Python version, while additionally running on Python 3.13+/3.14 and having Sentry/OTLP built in. Picologging exists and is good; LogXide's edge is the extra reach and integrations.
177
177
 
178
178
  Full benchmarks with methodology are [on GitHub](https://github.com/Indosaram/logxide/blob/main/docs/benchmarks.md).
179
179
 
@@ -6,7 +6,7 @@ The test suite had been running for 47 seconds when it stopped. No error. No out
6
6
 
7
7
  I stared at the terminal. The cursor wasn't blinking. The progress bar had frozen mid-frame. I hit Ctrl+C. Nothing. I hit it again, harder, as if that would help. The process was deadlocked somewhere deep in the call stack, and I had no idea where.
8
8
 
9
- This was LogXide, my Rust-powered drop-in replacement for Python's logging module. I'd spent weeks making it up to 13× faster than stdlib. The benchmarks were beautiful. Then I merged to main, and everything caught fire.
9
+ This was LogXide, my Rust-powered, largely stdlib-compatible logging library. I'd spent weeks making it several-fold faster than stdlib. The benchmarks were beautiful. Then I merged to main, and everything caught fire.
10
10
 
11
11
  If you haven't read Part 1, it covers what LogXide actually does: you `pip install logxide`, replace `import logging` with `from logxide import logging`, and suddenly your log calls drop from ~6 microseconds to ~0.5 microseconds. Same API, same handlers, same everything — just Rust underneath. It works with Flask, Django, FastAPI, Sentry, OTLP. That's the happy path. This is the story of how I almost never got there.
12
12
 
@@ -1,5 +1,7 @@
1
1
  """
2
- LogXide: High-performance, Rust-powered drop-in replacement for Python's logging module.
2
+ LogXide: high-performance, Rust-powered logging with a largely stdlib-compatible
3
+ API. A near-drop-in for common patterns; some advanced stdlib scenarios differ
4
+ (see docs/compatibility.md).
3
5
  """
4
6
 
5
7
  import os
@@ -43,7 +45,7 @@ _check_python_version()
43
45
 
44
46
  from . import logxide
45
47
 
46
- __version__ = "0.2.1"
48
+ __version__ = "0.2.2"
47
49
 
48
50
  from . import logxide as _logxide_ext
49
51
  from .compat_functions import (
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "logxide"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "High-performance Python logging — Rust-powered, stdlib-compatible API"
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}
@@ -31,6 +31,13 @@ thread_local! {
31
31
  /// each format call only pays a single bounded `String::clone` instead of
32
32
  /// growing a fresh allocation from zero. Cleared on entry, cloned on exit.
33
33
  static FMT_SCRATCH: RefCell<String> = const { RefCell::new(String::new()) };
34
+
35
+ /// Per-thread cache of the default-format asctime keyed on the truncated epoch
36
+ /// second. The default "%Y-%m-%d %H:%M:%S" has no sub-second field, so its output
37
+ /// is constant within one second — reused here to skip repeated chrono formatting.
38
+ /// Only used for the default format; custom datefmt (which may carry %f) is never cached.
39
+ static ASCTIME_SECOND_CACHE: RefCell<(i64, String)> =
40
+ const { RefCell::new((i64::MIN, String::new())) };
34
41
  }
35
42
 
36
43
  pub trait Formatter: Send + Sync {
@@ -377,17 +384,29 @@ impl PythonFormatter {
377
384
  }
378
385
  "asctime" => {
379
386
  let s = asctime_cache.get_or_insert_with(|| {
380
- let datetime = chrono::Local
381
- .timestamp_opt(
382
- record.created as i64,
383
- (record.msecs * 1_000_000.0) as u32,
384
- )
385
- .single()
386
- .unwrap_or_else(chrono::Local::now);
387
387
  if let Some(date_fmt) = date_format {
388
+ let datetime = chrono::Local
389
+ .timestamp_opt(
390
+ record.created as i64,
391
+ (record.msecs * 1_000_000.0) as u32,
392
+ )
393
+ .single()
394
+ .unwrap_or_else(chrono::Local::now);
388
395
  datetime.format(date_fmt).to_string()
389
396
  } else {
390
- datetime.format("%Y-%m-%d %H:%M:%S").to_string()
397
+ let sec = record.created as i64;
398
+ ASCTIME_SECOND_CACHE.with(|cell| {
399
+ let mut cached = cell.borrow_mut();
400
+ if cached.0 != sec {
401
+ let datetime = chrono::Local
402
+ .timestamp_opt(sec, 0)
403
+ .single()
404
+ .unwrap_or_else(chrono::Local::now);
405
+ cached.1 = datetime.format("%Y-%m-%d %H:%M:%S").to_string();
406
+ cached.0 = sec;
407
+ }
408
+ cached.1.clone()
409
+ })
391
410
  }
392
411
  });
393
412
  s.as_str()
@@ -57,6 +57,19 @@ pub fn check_level(py: Python, level: &Bound<PyAny>) -> PyResult<u32> {
57
57
  level.repr()?
58
58
  )))
59
59
  }
60
+
61
+ /// Coerce a log `msg` to `String` like `str(msg)`. Exact-`str` fast path reads the
62
+ /// UTF-8 buffer directly and skips `PyObject_Str`; the exact-type check is required for
63
+ /// byte-identical output because `str` subclasses may override `__str__`.
64
+ #[inline]
65
+ fn coerce_msg_to_string(msg: &Bound<PyAny>) -> PyResult<String> {
66
+ if msg.is_exact_instance_of::<pyo3::types::PyString>() {
67
+ Ok(msg.cast::<pyo3::types::PyString>()?.to_string())
68
+ } else {
69
+ Ok(msg.str()?.to_string())
70
+ }
71
+ }
72
+
60
73
  pub fn py_to_json_value(obj: &Bound<PyAny>) -> Value {
61
74
  if obj.is_none() {
62
75
  Value::Null
@@ -858,7 +871,7 @@ impl PyLogger {
858
871
  return Ok(());
859
872
  }
860
873
  let extra_fields = self.extract_extra_fields(kwargs);
861
- let msg_str = msg.bind(py).str()?.to_string();
874
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
862
875
  let serialized_args = self.serialize_args(py, args);
863
876
  let mut record = create_log_record_with_extra(
864
877
  self.fast_logger.name.to_string(),
@@ -886,7 +899,7 @@ impl PyLogger {
886
899
  return Ok(());
887
900
  }
888
901
  let extra_fields = self.extract_extra_fields(kwargs);
889
- let msg_str = msg.bind(py).str()?.to_string();
902
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
890
903
  let serialized_args = self.serialize_args(py, args);
891
904
  let mut record = create_log_record_with_extra(
892
905
  self.fast_logger.name.to_string(),
@@ -914,7 +927,7 @@ impl PyLogger {
914
927
  return Ok(());
915
928
  }
916
929
  let extra_fields = self.extract_extra_fields(kwargs);
917
- let msg_str = msg.bind(py).str()?.to_string();
930
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
918
931
  let serialized_args = self.serialize_args(py, args);
919
932
  let mut record = create_log_record_with_extra(
920
933
  self.fast_logger.name.to_string(),
@@ -942,7 +955,7 @@ impl PyLogger {
942
955
  return Ok(());
943
956
  }
944
957
  let extra_fields = self.extract_extra_fields(kwargs);
945
- let msg_str = msg.bind(py).str()?.to_string();
958
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
946
959
  let serialized_args = self.serialize_args(py, args);
947
960
  let mut record = create_log_record_with_extra(
948
961
  self.fast_logger.name.to_string(),
@@ -970,7 +983,7 @@ impl PyLogger {
970
983
  return Ok(());
971
984
  }
972
985
  let extra_fields = self.extract_extra_fields(kwargs);
973
- let msg_str = msg.bind(py).str()?.to_string();
986
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
974
987
  let serialized_args = self.serialize_args(py, args);
975
988
  let mut record = create_log_record_with_extra(
976
989
  self.fast_logger.name.to_string(),
@@ -998,7 +1011,7 @@ impl PyLogger {
998
1011
  return Ok(());
999
1012
  }
1000
1013
  let extra_fields = self.extract_extra_fields(kwargs);
1001
- let msg_str = msg.bind(py).str()?.to_string();
1014
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
1002
1015
  let serialized_args = self.serialize_args(py, args);
1003
1016
  let mut record = create_log_record_with_extra(
1004
1017
  self.fast_logger.name.to_string(),
@@ -1028,7 +1041,7 @@ impl PyLogger {
1028
1041
  return Ok(());
1029
1042
  }
1030
1043
  let extra_fields = self.extract_extra_fields(kwargs);
1031
- let msg_str = msg.bind(py).str()?.to_string();
1044
+ let msg_str = coerce_msg_to_string(msg.bind(py))?;
1032
1045
  let serialized_args = self.serialize_args(py, args);
1033
1046
  let mut record = create_log_record_with_extra(
1034
1047
  self.fast_logger.name.to_string(),
@@ -118,3 +118,47 @@ class TestHandlerOutput:
118
118
  finally:
119
119
  if os.path.exists(temp_file):
120
120
  os.unlink(temp_file)
121
+
122
+ def test_non_str_msg_still_coerces_via_str(self):
123
+ """Regression guard for the M3 exact-str fast path: non-str msg objects
124
+ must still be coerced with str(), byte-identical to Python logging."""
125
+ import time
126
+
127
+ from logxide import logging
128
+
129
+ with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".log") as f:
130
+ temp_file = f.name
131
+
132
+ class CustomStr:
133
+ def __str__(self):
134
+ return "custom-str-value"
135
+
136
+ try:
137
+ logging.basicConfig(
138
+ filename=temp_file,
139
+ level=logging.INFO,
140
+ format="%(message)s",
141
+ force=True,
142
+ )
143
+ logger = logging.getLogger("test.coerce")
144
+
145
+ logger.info(123) # type: ignore[arg-type]
146
+ logger.info(CustomStr()) # type: ignore[arg-type]
147
+ logger.info(["a", "b"]) # type: ignore[arg-type]
148
+ logger.info("plain str")
149
+
150
+ logging.flush()
151
+ time.sleep(0.2)
152
+
153
+ with open(temp_file) as f:
154
+ lines = f.read().splitlines()
155
+
156
+ assert lines == [
157
+ "123",
158
+ "custom-str-value",
159
+ "['a', 'b']",
160
+ "plain str",
161
+ ]
162
+ finally:
163
+ if os.path.exists(temp_file):
164
+ os.unlink(temp_file)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes