syntropylog 0.10.1 → 0.11.0

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 (35) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/CONTRIBUTING.md +4 -0
  3. package/README.md +54 -4
  4. package/dist/index.cjs +470 -130
  5. package/dist/index.d.ts +311 -87
  6. package/dist/index.mjs +473 -131
  7. package/dist/testing/index.cjs +29 -15
  8. package/dist/testing/index.d.ts +43 -55
  9. package/dist/testing/index.mjs +29 -15
  10. package/dist/types/SyntropyLog.d.ts +2 -0
  11. package/dist/types/config.schema.d.ts +10 -0
  12. package/dist/types/constants.d.ts +31 -0
  13. package/dist/types/context/ContextManager.d.ts +2 -5
  14. package/dist/types/index.d.ts +2 -0
  15. package/dist/types/internal-types.d.ts +14 -6
  16. package/dist/types/logger/ILogger.d.ts +9 -8
  17. package/dist/types/logger/Logger.d.ts +16 -12
  18. package/dist/types/logger/LoggerFactory.d.ts +3 -0
  19. package/dist/types/logger/adapters/UniversalAdapter.d.ts +6 -2
  20. package/dist/types/logger/transports/AdapterTransport.d.ts +3 -3
  21. package/dist/types/logger/transports/BaseConsolePrettyTransport.d.ts +3 -4
  22. package/dist/types/logger/transports/ConsoleTransport.d.ts +3 -5
  23. package/dist/types/logger/transports/SpyTransport.d.ts +3 -3
  24. package/dist/types/logger/transports/Transport.d.ts +3 -4
  25. package/dist/types/logger/transports/adapter.types.d.ts +3 -4
  26. package/dist/types/masking/MaskingEngine.d.ts +7 -16
  27. package/dist/types/sanitization/SanitizationEngine.d.ts +4 -4
  28. package/dist/types/serialization/SerializationManager.d.ts +28 -1
  29. package/dist/types/serialization/SerializationPipeline.d.ts +6 -7
  30. package/dist/types/serialization/pipeline/SerializationStep.d.ts +2 -2
  31. package/dist/types/serialization/types.d.ts +1 -1
  32. package/dist/types/testing/MockSyntropyLog.d.ts +4 -7
  33. package/dist/types/type-exports.d.ts +12 -2
  34. package/dist/types/types.d.ts +5 -21
  35. package/package.json +9 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - - **Native addon (Rust):** `fastSerializeFromJson(level, message, timestamp, service, metadataJson)` for single N-API cross when metadata is JSON-serializable; fallback to `fastSerialize` on error. SerializationManager uses this path when `JSON.stringify(metadata)` succeeds.
8
+ - **Docs:** Benchmark reports (EN/ES) updated; new "Scope and interpretation of results" section (representative workloads, 10M+ note). CONTRIBUTING: CI runs on branches, Release only on main.
9
+ - **CI:** Reproducible lockfile (no machine-specific `link:`); benchmark job uses `bench:memory` for stable memory; build-native and test-node.mjs fixed for current addon API.
10
+ - **Security:** pnpm override for `flatted` >= 3.4.0 (GHSA-25h7-pfq9-p65f).
11
+ - **Tests:** Branch coverage raised to meet 80% threshold (internal-types, SerializationManager metrics and native paths).
12
+
3
13
  ## 0.10.1
4
14
 
5
15
  ### Patch Changes
package/CONTRIBUTING.md CHANGED
@@ -88,6 +88,10 @@ We welcome code contributions! To contribute code, please follow these steps:
88
88
 
89
89
  ## Release process (maintainers)
90
90
 
91
+ **Ramas auxiliares (feature, develop, etc.):** en cada push y en los PRs se ejecuta solo el workflow **CI** (lint, build, tests, benchmark con addon nativo). No se publica nada en npm. Así puedes validar que todo pase antes de integrar a `main`.
92
+
93
+ **Solo al hacer push a `main`** se ejecuta el workflow **Release** (build del addon en todas las plataformas y, si hay changesets, versionado/publicación en npm).
94
+
91
95
  Releases use [Changesets](https://github.com/changesets/changesets) and GitHub Actions. **Para que la versión suba en npm, siempre tienes que hacer una de estas dos cosas:**
92
96
 
93
97
  ### Opción A: Usar el PR que crea el action
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
  <a href="https://github.com/Syntropysoft/SyntropyLog/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/syntropylog.svg" alt="License"></a>
18
18
  <a href="https://github.com/Syntropysoft/SyntropyLog/actions/workflows/ci.yaml"><img src="https://github.com/Syntropysoft/SyntropyLog/actions/workflows/ci.yaml/badge.svg" alt="CI Status"></a>
19
19
  <a href="#"><img src="https://img.shields.io/badge/coverage-95.13%25-brightgreen" alt="Test Coverage"></a>
20
- <a href="#"><img src="https://img.shields.io/badge/status-v0.10.0-brightgreen.svg" alt="Version 0.10.0"></a>
20
+ <a href="#"><img src="https://img.shields.io/badge/status-v0.11.0-brightgreen.svg" alt="Version 0.11.0"></a>
21
21
  <a href="https://socket.dev/npm/package/syntropylog"><img src="https://socket.dev/api/badge/npm/package/syntropylog" alt="Socket Badge"></a>
22
22
  </p>
23
23
 
@@ -37,8 +37,9 @@ That means:
37
37
  - An **Intelligent Serialization Pipeline** that automatically detects and neutralizes circular references, limits object depth, and enforces execution timeouts — making logs immune to application crashes.
38
38
  - A **UniversalAdapter** that routes logs to any backend (PostgreSQL, MongoDB, Elasticsearch, S3) via a single `executor` function — no coupling, no lock-in.
39
39
  - A **SanitizationEngine** that strips control characters from all log output, preventing log injection attacks.
40
+ - **Lightning Speed**: Optimized core pipeline delivering **~1,000,000 ops/s** even with full masking and context.
40
41
 
41
- **This is not about performance benchmarks. It's about giving your team full declarative control over observability data what flows, where it goes, and what it means.**
42
+ **This is not just another logger. It's about giving your team full declarative control over observability data with industry-leading performance and reliability.**
42
43
 
43
44
  ### Built for regulated industries
44
45
 
@@ -57,12 +58,35 @@ We ship with `sideEffects: false` and ESM so bundlers (Vite, Rollup, webpack, es
57
58
 
58
59
  Traditional loggers (and even modern ones) share a common weakness: **serialization is a blocking operation**. If you log a massive, deeply nested, or circular object, the Node.js Event Loop stops. Your API stops responding. Your service might even crash with a `TypeError`.
59
60
 
60
- SyntropyLog v0.10.0 introduces the **Log Resilience Engine**, making your application immune to "Death by Log":
61
+ SyntropyLog v0.11.0 introduces the **Log Resilience Engine**, making your application immune to "Death by Log":
61
62
 
62
63
  1. **Event Loop Protection**: Every serialization step is wrapped in a mandatory timeout (default: **50ms**). If serialization takes too long, it is aborted via `Promise.race`, and a safe subset of the data is logged instead. Your app keeps running.
63
64
  2. **Circular Reference Immunity**: Built-in hygiene automatically detects and neutralizes circular references. No more `TypeError: Converting circular structure to JSON`.
64
- 3. **Configurable Performance**: 50ms is the safe default, but it's fully configurable via `serializerTimeoutMs`. You control the balance between log detail and application performance.
65
+ 3. **Configurable Safety Limits**: Every object is protected by a double-guard:
66
+ - `serializationMaxDepth` (default: **10**): Automatically truncates objects deeper than this to prevent Stack Overflow.
67
+ - `serializationMaxBreadth` (default: **100**): Limits arrays and object keys to prevent Event Loop blockage on massive structures.
65
68
  4. **Silent Observer**: Logging should never throw. Our pipeline catches and reports its own failures inside the log message itself, ensuring 100% reliability.
69
+ 5. **Lightning Pipeline**: Consolidation of serialization, masking, and sanitization into a single recursive pass, reaching Pino-level efficiency with Enterprise-level security.
70
+
71
+ > [!WARNING]
72
+ > **Pathological Object Protection**: When an object exceeds the configured Depth or Breadth, it will be automatically truncated (e.g., `[Max Depth reached]` or `[Truncated 500 items]`). This is a feature, not a bug — it ensures your application survives even when buggy code tries to log half the database!
73
+
74
+ ---
75
+
76
+ ## 📊 Performance Benchmarks
77
+
78
+ Tested with **2,000,000 logs** on Node.js 20+ (Nulled I/O).
79
+
80
+ | Library | Throughput | Avg Latency | Notes |
81
+ | :--- | :--- | :--- | :--- |
82
+ | **Pino** | ~4.1M ops/s | 0.24 µs | Fastest, no masking by default |
83
+ | **SyntropyLog v0.11.0** | **~980k ops/s** | **1.02 µs** | **Secure-by-default (Masking + Context)** |
84
+ | **Console.log** | ~1.2M ops/s | 0.83 µs | Baseline Node.js performance |
85
+ | **Winston** | ~175k ops/s | 5.70 µs | Traditional legacy logger |
86
+
87
+ > SyntropyLog is **5.5x faster than Winston** and only ~20% slower than pure console while providing deep-object masking and context management.
88
+
89
+ To compare native addon vs JS-only pipeline: run `pnpm run bench` (with addon) and `SYNTROPYLOG_NATIVE_DISABLE=1 pnpm run bench` (JS only). The benchmark reports "native addon (Rust): yes/no" at startup.
66
90
 
67
91
  ---
68
92
 
@@ -73,6 +97,8 @@ SyntropyLog v0.10.0 introduces the **Log Resilience Engine**, making your applic
73
97
  npm install syntropylog
74
98
  ```
75
99
 
100
+ For the best performance, the package includes **prebuilt native addon binaries (Rust)** for Linux, Windows, and macOS; they install automatically on supported platforms. If the addon is unavailable (e.g. unsupported Node version or platform), the framework falls back to the JS pipeline transparently.
101
+
76
102
  ### **Available Console Transports**
77
103
 
78
104
  By default, SyntropyLog outputs **lightweight plain JSON to the console — automatically, with no configuration needed**. No imports, no setup, no extra dependencies.
@@ -177,6 +203,22 @@ const logger = syntropyLog.getLogger();
177
203
  logger.info('System is clean and ready.');
178
204
  ```
179
205
 
206
+ ### **Optional error and fallback hooks**
207
+
208
+ You can pass optional callbacks in the config for observability (logging never throws; these hooks let you observe failures):
209
+
210
+ | Hook | When it is called |
211
+ |------|--------------------|
212
+ | `onLogFailure?(error, entry)` | When a log call fails (serialization or transport error). |
213
+ | `onTransportError?(error, context)` | When a transport fails (flush, shutdown, or log write). `context` is `'flush'`, `'shutdown'`, or `'log'`. |
214
+ | `onSerializationFallback?(reason)` | When the native addon is used but fails for a call and the framework falls back to the JS pipeline. |
215
+ | `onStepError?(step, error)` | When a pipeline step fails (e.g. hygiene). |
216
+ | `masking.onMaskingError?(error)` | When masking fails (e.g. timeout); never receives raw payload. |
217
+
218
+ Use `onSerializationFallback` to detect when the native addon failed for a given call and the JS pipeline was used instead (e.g. for metrics or alerting). You can also call `syntropyLog.isNativeAddonInUse()` at runtime to check if the Rust addon is loaded.
219
+
220
+ Example: `syntropyLog.init({ onLogFailure: (err) => metrics.increment('log_failures'), ... });`
221
+
180
222
  ### **3. Graceful Shutdown (Essential)**
181
223
  ```typescript
182
224
  async function gracefulShutdown() {
@@ -617,6 +659,14 @@ const dbTransport = new UniversalAdapter({
617
659
 
618
660
  ---
619
661
 
662
+ ## 📚 Documentation
663
+
664
+ - **[Improvement plan & roadmap](docs/code-improvement-analysis-and-plan.md)** — Code analysis, prioritized backlog, and phased work plan.
665
+ - **[Rust addon implementation plan](doc-es/rust-implementation-plan.md)** (ES) — Phased checklist to maximize use of the native addon (“Formula 1” path); links to [rust-pipeline-optimization.md](doc-es/rust-pipeline-optimization.md) for details.
666
+ - **Benchmarks** — Summary in the [Performance Benchmarks](#-performance-benchmarks) section above; run `pnpm run bench` or `pnpm run bench:memory` from the repo root. [Benchmark run report (throughput + memory + high-demand stack)](docs/benchmark-memory-run.md) (EN) · [Informe de ejecución (ES)](doc-es/benchmark-memory-run.md). With the optional Rust addon built (`cd syntropylog-native && pnpm run build`), the benchmark reports native addon usage.
667
+
668
+ ---
669
+
620
670
  ## 🤝 Contributing & License
621
671
 
622
672
  We love contributors! Check our [Contributing Guide](./CONTRIBUTING.md).