syntropylog 0.7.4 β†’ 0.8.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 (78) hide show
  1. package/README.md +729 -397
  2. package/dist/brokers/index.d.ts +7 -0
  3. package/dist/config.schema.js +8 -9
  4. package/dist/config.schema.js.map +1 -1
  5. package/dist/http/index.d.ts +7 -0
  6. package/dist/index.cjs +213 -23
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +14 -21
  9. package/dist/index.js +4 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +211 -24
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/logger/Logger.js +15 -4
  14. package/dist/logger/Logger.js.map +1 -1
  15. package/dist/logger/LoggerFactory.js +21 -9
  16. package/dist/logger/LoggerFactory.js.map +1 -1
  17. package/dist/logger/adapters/UniversalAdapter.js +30 -0
  18. package/dist/logger/adapters/UniversalAdapter.js.map +1 -0
  19. package/dist/logger/formatters/UniversalLogFormatter.js +81 -0
  20. package/dist/logger/formatters/UniversalLogFormatter.js.map +1 -0
  21. package/dist/logger/levels.js +1 -0
  22. package/dist/logger/levels.js.map +1 -1
  23. package/dist/logger/transports/AdapterTransport.js +55 -0
  24. package/dist/logger/transports/AdapterTransport.js.map +1 -0
  25. package/dist/logger/transports/ClassicConsoleTransport.js +3 -2
  26. package/dist/logger/transports/ClassicConsoleTransport.js.map +1 -1
  27. package/dist/logger/transports/CompactConsoleTransport.js +1 -0
  28. package/dist/logger/transports/CompactConsoleTransport.js.map +1 -1
  29. package/dist/logger/transports/PrettyConsoleTransport.js +1 -0
  30. package/dist/logger/transports/PrettyConsoleTransport.js.map +1 -1
  31. package/dist/logger/transports/adapter.types.js +2 -0
  32. package/dist/logger/transports/adapter.types.js.map +1 -0
  33. package/dist/redis/BeaconRedisMock.js +1 -0
  34. package/dist/redis/BeaconRedisMock.js.map +1 -1
  35. package/dist/serialization/pipeline/SerializationStep.js +5 -5
  36. package/dist/serialization/pipeline/SerializationStep.js.map +1 -1
  37. package/dist/testing/index.cjs +1 -0
  38. package/dist/testing/index.cjs.map +1 -1
  39. package/dist/testing/index.d.ts +1 -0
  40. package/dist/testing/index.mjs +1 -0
  41. package/dist/testing/index.mjs.map +1 -1
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/dist/types/config.schema.d.ts +7 -21
  44. package/dist/types/index.d.ts +3 -0
  45. package/dist/types/logger/ILogger.d.ts +6 -0
  46. package/dist/types/logger/Logger.d.ts +5 -0
  47. package/dist/types/logger/LoggerFactory.d.ts +1 -1
  48. package/dist/types/logger/adapters/UniversalAdapter.d.ts +22 -0
  49. package/dist/types/logger/formatters/UniversalLogFormatter.d.ts +32 -0
  50. package/dist/types/logger/levels.d.ts +1 -0
  51. package/dist/types/logger/transports/AdapterTransport.d.ts +48 -0
  52. package/dist/types/logger/transports/adapter.types.d.ts +28 -0
  53. package/package.json +64 -13
  54. package/dist/cli/audit.js +0 -58
  55. package/dist/cli/audit.js.map +0 -1
  56. package/dist/cli/checks.js +0 -164
  57. package/dist/cli/checks.js.map +0 -1
  58. package/dist/cli/cli.js +0 -112
  59. package/dist/cli/cli.js.map +0 -1
  60. package/dist/cli/doctor.js +0 -125
  61. package/dist/cli/doctor.js.map +0 -1
  62. package/dist/cli/init.js +0 -131
  63. package/dist/cli/init.js.map +0 -1
  64. package/dist/cli/templates.js +0 -91
  65. package/dist/cli/templates.js.map +0 -1
  66. package/dist/doctor.cjs +0 -140
  67. package/dist/doctor.cjs.map +0 -1
  68. package/dist/doctor.js +0 -23
  69. package/dist/doctor.js.map +0 -1
  70. package/dist/doctor.mjs +0 -138
  71. package/dist/doctor.mjs.map +0 -1
  72. package/dist/types/cli/audit.d.ts +0 -6
  73. package/dist/types/cli/checks.d.ts +0 -47
  74. package/dist/types/cli/cli.d.ts +0 -2
  75. package/dist/types/cli/doctor.d.ts +0 -29
  76. package/dist/types/cli/init.d.ts +0 -22
  77. package/dist/types/cli/templates.d.ts +0 -20
  78. package/dist/types/doctor.d.ts +0 -27
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ # SyntropyLog
2
+
1
3
  <p align="center">
2
4
  <img src="./assets/beaconLog-2.png" alt="SyntropyLog Logo" width="170"/>
3
5
  </p>
@@ -7,86 +9,75 @@
7
9
  <p align="center">
8
10
  <strong>From Chaos to Clarity</strong>
9
11
  <br />
10
- The Observability Framework for High-Performance Teams
12
+ The Instance Manager with Observability for High-Performance Teams
11
13
  </p>
12
14
 
13
15
  <p align="center">
14
16
  <a href="https://www.npmjs.com/package/syntropylog"><img src="https://img.shields.io/npm/v/syntropylog.svg" alt="NPM Version"></a>
15
17
  <a href="https://github.com/Syntropysoft/SyntropyLog/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/syntropylog.svg" alt="License"></a>
16
18
  <a href="#"><img src="https://img.shields.io/badge/coverage-88.93%25-brightgreen" alt="Test Coverage"></a>
17
- <a href="#"><img src="https://img.shields.io/badge/status-beta-blue.svg" alt="Beta"></a>
19
+ <a href="#"><img src="https://img.shields.io/badge/status-rc_1-orange.svg" alt="RC 1"></a>
18
20
  <a href="https://github.com/Syntropysoft/SyntropyLog/actions/workflows/codeql.yml"><img src="https://github.com/Syntropysoft/SyntropyLog/workflows/CodeQL/badge.svg" alt="CodeQL"></a>
19
21
  <a href="https://github.com/Syntropysoft/SyntropyLog/security/advisories"><img src="https://img.shields.io/badge/dependabot-enabled-brightgreen.svg" alt="Dependabot"></a>
20
22
  </p>
21
23
 
22
24
  ---
23
25
 
24
- ### πŸ”’ Security & Transparency
25
-
26
- **We invite any member of the community to audit the code. If you find anything suspicious, please open an issue or a pull request.
27
- We take security and transparency very seriously.**
26
+ ## 🌟 What's New in v0.8.0
28
27
 
29
- - 100% open source and public.
30
- - No hidden telemetry, tracking, or obfuscated code.
31
- - Automated dependency and vulnerability scans via GitHub Dependabot and CodeQL.
32
- - High code coverage and comprehensive testing.
33
- - External and community audits are welcome.
28
+ The **Universal Persistence Update** simplifies how developers connect SyntropyLog to any database without external adapters.
34
29
 
35
- If you have any questions or feedback, feel free to reach out or contribute!
30
+ - **πŸš€ Universal Persistence**: Use `UniversalAdapter` + `UniversalLogFormatter` to map logs to any schema (SQL/NoSQL) using pure JSON mapping.
31
+ - **πŸ›‘οΈ First-Class Audit Level**: A new `audit()` method designed for compliance and long-term storage, bypassing standard severity filters.
32
+ - **🎨 Enhanced Console UI**: Beautifully colorized output for the `audit` level across all console transports.
36
33
 
37
34
  ---
38
35
 
36
+
39
37
  ## πŸ“‹ Table of Contents
40
38
 
41
- - [πŸ“‹ Table of Contents](#-table-of-contents)
42
- - [πŸš€ Quick Start](#-quick-start)
39
+ - [🎯 What is SyntropyLog?](#-what-is-syntropylog)
40
+ - [πŸš€ Quick Start (30 seconds)](#-quick-start-30-seconds)
41
+ - [🏒 Enterprise Implementation Guide](#-enterprise-implementation-guide)
42
+ - [πŸ“š Manual & Tutorials](#-manual--tutorials)
43
43
  - [✨ Key Features](#-key-features)
44
- - [πŸ“Š Performance \& Benchmarks](#-performance--benchmarks)
45
- - [πŸ† The Double Victory: Benchmark Evidence](#-the-double-victory-benchmark-evidence)
46
- - [πŸš€ Victory #1: Zero Overhead Core](#-victory-1-zero-overhead-core)
47
- - [🎯 Victory #2: Intelligent Tree-Shaking](#-victory-2-intelligent-tree-shaking)
48
- - [πŸ—οΈ Beyond a Logger: An Orchestration Framework](#️-beyond-a-logger-an-orchestration-framework)
49
- - [🎯 Positioning \& Final Verdict](#-positioning--final-verdict)
44
+ - [πŸ“Š Performance & Benchmarks](#-performance--benchmarks)
50
45
  - [🎭 Core Philosophy: Silent Observer](#-core-philosophy-silent-observer)
51
- - [🚫 Never Interrupts Your Application](#-never-interrupts-your-application)
52
- - [πŸ” What Happens When Logging Fails](#-what-happens-when-logging-fails)
53
- - [πŸ“‘ Error Reporting Strategy](#-error-reporting-strategy)
54
- - [πŸ“š Documentation](#-documentation)
55
- - [🎯 Production Ready](#-production-ready)
56
- - [πŸ“ Version Notes](#-version-notes)
57
- - [πŸ”§ Standard Configuration](#-standard-configuration)
58
- - [πŸš€ Simple Example: Automatic Context Propagation](#-simple-example-automatic-context-propagation)
59
- - [πŸ—οΈ Singleton Pattern - Intelligent Resource Management](#️-singleton-pattern---intelligent-resource-management)
60
- - [**🎯 Named Instance Management**](#-named-instance-management)
61
- - [**πŸ“ Loggers - On-Demand Creation with Singleton Management**](#-loggers---on-demand-creation-with-singleton-management)
62
- - [**πŸ”— Infrastructure Resources - Pre-configured Singletons**](#-infrastructure-resources---pre-configured-singletons)
63
- - [**πŸ”„ Automatic Resource Lifecycle**](#-automatic-resource-lifecycle)
64
- - [**πŸ“ Logger Lifecycle (On-Demand)**](#-logger-lifecycle-on-demand)
65
- - [**πŸ”— Infrastructure Lifecycle (Pre-configured)**](#-infrastructure-lifecycle-pre-configured)
66
- - [**⚑ Production Benefits**](#-production-benefits)
67
- - [πŸ§ͺ Testing Revolution](#-testing-revolution)
68
- - [**🎯 Zero Boilerplate Testing with SyntropyLogMock**](#-zero-boilerplate-testing-with-syntropylogmock)
69
- - [**πŸš€ What's New in v0.7.0**](#-whats-new-in-v070)
70
- - [**βœ… Benefits**](#-benefits)
71
- - [πŸ“¦ Ecosystem](#-ecosystem)
72
- - [πŸš€ Examples](#-examples)
73
- - [βœ… **Complete \& Tested (00-13, 20-24, 28-32)**](#-complete--tested-00-13-20-24-28-32)
74
- - [🚧 **In Development (14-19, 25-27)**](#-in-development-14-19-25-27)
46
+ - [πŸ”§ Configuration Guide](#-configuration-guide)
47
+ - [πŸ§ͺ Testing Guide](#-testing-guide)
48
+ - [πŸ“¦ Examples & Ecosystem](#-examples--ecosystem)
49
+ - [πŸ”’ Security & Transparency](#-security--transparency)
75
50
  - [🀝 Contributing](#-contributing)
76
51
  - [πŸ“„ License](#-license)
77
- - [πŸ“ž Support](#-support)
78
-
79
52
 
80
53
  ---
81
54
 
82
- ## πŸš€ Quick Start
55
+ ## 🎯 What is SyntropyLog?
56
+
57
+ **SyntropyLog is an instance manager with observability for Node.js applications.** It's not just a logger - it's a complete system that manages your application instances, their connections, and provides complete observability across your entire system with zero performance overhead.
83
58
 
84
- Get started with SyntropyLog usage in **30 seconds** (after initialization):
59
+ ### **🎯 Key Benefits:**
60
+ - **Zero Performance Impact** - Identical performance to Pino (industry standard)
61
+ - **Automatic Context Propagation** - Correlation IDs flow through all operations
62
+ - **Singleton Resource Management** - Prevents memory leaks and connection issues
63
+ - **Enterprise Security** - Built-in data masking and compliance features
64
+ - **Framework Agnostic** - Works with Express, Fastify, Koa, NestJS, and any Node.js app
85
65
 
66
+ ### **πŸ”— Enterprise Integration & APM:**
67
+ - **Currently, SyntropyLog does not include native APM**, but the architecture allows adding custom transports to integrate with enterprise tools
68
+ - **Ideal for teams** already using Jaeger, Zipkin, Elastic, or Prometheus who want to enrich their observability without vendor lock-in
69
+ - **Custom transport support** enables seamless integration with your existing monitoring stack
70
+
71
+ ---
72
+
73
+ ## πŸš€ Quick Start (30 seconds)
74
+
75
+ ### **Step 1: Install**
86
76
  ```bash
87
77
  npm install syntropylog
88
78
  ```
89
79
 
80
+ ### **Step 2: Basic Setup**
90
81
  ```typescript
91
82
  import { syntropyLog } from 'syntropylog';
92
83
 
@@ -102,410 +93,673 @@ await syntropyLog.init({
102
93
  const logger = syntropyLog.getLogger();
103
94
  logger.info('Hello, SyntropyLog!');
104
95
  ```
105
- // Note: This shows the "zero boilerplate" usage pattern.
106
- // Initialization and shutdown require the boilerplate shown in the documentation.
107
96
 
108
- > ⚠️ **CRITICAL REQUIREMENT**: You **MUST** include the [graceful shutdown boilerplate](https://syntropysoft.github.io/syntropylog-doc/docs/production/graceful-shutdown) in ALL applications. This ensures logs are flushed and resources are cleaned up when:
109
- > - **Development**: You press Ctrl+C to stop the application
110
- > - **Production**: Kubernetes sends SIGTERM to terminate your pod
97
+ ### **Step 3: Add Graceful Shutdown (REQUIRED)**
98
+ ```typescript
99
+ // Add this to your main application file
100
+ process.on('SIGTERM', async () => {
101
+ console.log('πŸ”„ Shutting down gracefully...');
102
+ await syntropyLog.shutdown();
103
+ process.exit(0);
104
+ });
111
105
 
112
- ## ✨ Key Features
106
+ process.on('SIGINT', async () => {
107
+ console.log('πŸ”„ Shutting down gracefully...');
108
+ await syntropyLog.shutdown();
109
+ process.exit(0);
110
+ });
111
+ ```
113
112
 
114
- - **πŸ”„ Zero Boilerplate** - Get started in 30 seconds with automatic context propagation (usage only - initialization/shutdown boilerplate required)
115
- - **πŸ”— Automatic Correlation** - Distributed tracing across services, HTTP calls, and message brokers
116
- - **🎯 Framework Agnostic** - Works with Express, Fastify, Koa, NestJS, and any Node.js app
117
- - **πŸ›‘οΈ Security First** - Built-in data masking and compliance-ready logging
118
- - **⚑ High Performance** - 45,000+ ops/sec with less than 1ms latency
119
- - **πŸ—οΈ Singleton Pattern** - Prevents pod crashes by managing resource instances efficiently
113
+ > ⚠️ **CRITICAL**: You **MUST** include graceful shutdown in ALL applications. This ensures logs are flushed and resources are cleaned up when your application stops.
120
114
 
121
- ## πŸ“Š Performance & Benchmarks
115
+ ---
122
116
 
123
- **SyntropyLog is not simply a logger, but an observability orchestration framework for high-performance Node.js applications.** Our philosophy centers on being a "Silent Observer" that never interferes with application logic. Empirical benchmarks demonstrate that SyntropyLog achieves a remarkable technical milestone: offering advanced distributed tracing and instance management capabilities with **zero performance impact** and **minimal bundle size overhead**, thanks to a highly optimized core and effective tree-shaking architecture.
117
+ ## πŸ› οΈ CLI Tools
124
118
 
125
- ### πŸ† The Double Victory: Benchmark Evidence
119
+ **SyntropyLog CLI tools are now available as a separate package for better modularity and focused development.**
126
120
 
127
- Our comprehensive benchmark suite compares SyntropyLog's core (logger + context) against Pino (industry standard for speed) and a no-logger baseline. The results reveal two key strengths:
121
+ ### **Install CLI Tools**
122
+ ```bash
123
+ npm install -g @syntropysoft/praetorian
124
+ ```
128
125
 
129
- | Logger | Bundle Size (JS) | Perf. Time | vs No Logger (Size) | vs Pino (Size/Perf) |
130
- |--------|------------------|------------|---------------------|---------------------|
131
- | No Logger | 5 KB | 3 ms | - | - |
132
- | Pino | 5 KB | 2 ms | -193 B | - |
133
- | **SyntropyLog** | **5 KB** | **2 ms** | **+10 B** | **+203 B (1.03x) / +0 ms (1.00x)** |
126
+ ### **Available Commands**
127
+ - `praetorian doctor` - Diagnose your SyntropyLog configuration
128
+ - `praetorian init` - Initialize a new SyntropyLog project
129
+ - `praetorian audit` - Audit your logging configuration
130
+ - `praetorian validate` - Validate configuration files
134
131
 
135
- ### πŸš€ Victory #1: Zero Overhead Core
132
+ ### **Why Separate Package?**
133
+ - **Focused Development** - CLI tools evolve independently
134
+ - **Reduced Bundle Size** - Core library stays lightweight
135
+ - **Better Maintenance** - Dedicated team for CLI features
136
+ - **Faster Updates** - CLI updates don't require core library releases
136
137
 
137
- The most impressive metric is execution time. SyntropyLog, while managing context for traceability, **achieves identical performance to Pino** and is statistically indistinguishable from having no logger at all.
138
+ > πŸ“¦ **Note**: The CLI was previously included in this package but has been moved to `@syntropysoft/praetorian` for better modularity.
138
139
 
139
- **Conclusion**: SyntropyLog's core engine is so optimized that its performance cost is, in practice, **zero**. Teams can adopt advanced observability features without paying the "performance tax" typically associated with them.
140
+ ---
140
141
 
141
- ### 🎯 Victory #2: Intelligent Tree-Shaking
142
+ ## 🏒 Enterprise Implementation Guide
142
143
 
143
- The second victory is observed in bundle size. Adding SyntropyLog's core only increases bundle size by **203 bytes** compared to Pino, demonstrating the effectiveness of its modular architecture and tree-shaking. Developers only "pay" for the features they actually use in their code, without carrying the weight of HTTP orchestrators, Redis, or brokers if they don't use them.
144
+ **SyntropyLog is designed for enterprise environments and can be easily integrated into your internal infrastructure.**
144
145
 
145
- ### πŸ”’ Victory #3: Advanced Security with Zero Performance Impact
146
+ ### **🎯 Why SyntropyLog for Enterprise?**
146
147
 
147
- **Latest Benchmark Results (v0.7.1)**: Our comprehensive benchmark suite, including the new JSON flattening MaskingEngine, demonstrates that SyntropyLog maintains its performance excellence even with advanced security features:
148
+ 1. **πŸ”’ Security by Default**
149
+ - Built-in data masking for sensitive information
150
+ - Compliance-ready logging with retention rules
151
+ - No external telemetry or tracking
152
+ - 100% open source and auditable
148
153
 
149
- - **Bundle Size**: Only 203 bytes larger than Pino (1.03x)
150
- - **Performance**: Identical to Pino (1.00x performance ratio)
151
- - **Security**: Advanced data masking with JSON flattening strategy
152
- - **Stability**: Consistent results across multiple benchmark runs
154
+ 2. **πŸ—οΈ Scalable Architecture**
155
+ - Singleton pattern prevents resource leaks
156
+ - Automatic connection pooling
157
+ - Kubernetes-ready with proper lifecycle management
158
+ - Horizontal scaling support
153
159
 
154
- The MaskingEngine's JSON flattening strategy provides ultra-fast data masking at any object depth while maintaining the original structure, all with zero measurable performance impact.
160
+ 3. **⚑ Performance Excellence**
161
+ - Zero measurable performance overhead
162
+ - Minimal bundle size impact (only +203 bytes vs Pino)
163
+ - Optimized for high-throughput applications
155
164
 
156
- ### πŸ—οΈ Beyond a Logger: An Orchestration Framework
165
+ ### **🏒 Internal Implementation Strategy**
157
166
 
158
- SyntropyLog's true value proposition is understood by recognizing it's much more than a logger:
167
+ #### **Phase 1: Pilot Project (2-4 weeks)**
168
+ ```typescript
169
+ // Start with a single microservice
170
+ await syntropyLog.init({
171
+ logger: {
172
+ serviceName: 'user-service',
173
+ level: 'info',
174
+ },
175
+ context: {
176
+ correlationIdHeader: 'X-Correlation-ID',
177
+ },
178
+ redis: {
179
+ instances: [{
180
+ instanceName: 'cache',
181
+ url: process.env.REDIS_URL,
182
+ }]
183
+ }
184
+ });
185
+ ```
159
186
 
160
- - **Instance Management (Singleton)**: Prevents memory issues and inefficient connection usage by centrally managing HTTP, Redis, and message broker client instances
161
- - **Automatic Distributed Tracing**: Propagates correlation IDs across all orchestrated components, offering complete request flow visibility without manual effort
162
- - **Silent Observer Philosophy**: Ensures that logging system failures never interrupt or crash the main application
163
- - **Security & Compliance**: Offers advanced features like data masking and retention rules for enterprise environments
164
- - **Simplified Testing**: Provides a mock ecosystem (SyntropyLogMock) that eliminates the need for real connections in unit and integration tests, accelerating CI/CD cycles
187
+ #### **Phase 2: Service Mesh Integration (4-8 weeks)**
188
+ ```typescript
189
+ // Standardize across multiple services
190
+ const standardConfig = {
191
+ logger: {
192
+ level: process.env.LOG_LEVEL || 'info',
193
+ serviceName: process.env.SERVICE_NAME,
194
+ },
195
+ context: {
196
+ correlationIdHeader: 'X-Correlation-ID',
197
+ traceIdHeader: 'X-Trace-ID',
198
+ },
199
+ masking: {
200
+ fields: ['password', 'token', 'secret'],
201
+ preserveLength: true,
202
+ }
203
+ };
204
+ ```
165
205
 
166
- ### 🎯 Positioning & Final Verdict
206
+ #### **Phase 3: Enterprise Features (8-12 weeks)**
207
+ ```typescript
208
+ // Full enterprise configuration
209
+ await syntropyLog.init({
210
+ ...standardConfig,
211
+ redis: {
212
+ instances: [
213
+ { instanceName: 'cache', url: process.env.CACHE_REDIS_URL },
214
+ { instanceName: 'session', url: process.env.SESSION_REDIS_URL },
215
+ ]
216
+ },
217
+ brokers: {
218
+ instances: [
219
+ { instanceName: 'events', adapter: new KafkaAdapter(kafkaConfig) },
220
+ { instanceName: 'notifications', adapter: new RabbitMQAdapter(rabbitConfig) },
221
+ ]
222
+ },
223
+ http: {
224
+ instances: [
225
+ { instanceName: 'api', adapter: new AxiosAdapter(axiosConfig) },
226
+ ]
227
+ }
228
+ });
229
+ ```
167
230
 
168
- SyntropyLog has solved the classic observability trilemma: functionality, performance, and low impact. The data demonstrates that **no choice is necessary anymore**.
231
+ ### **πŸ”§ Enterprise Configuration Patterns**
169
232
 
170
- **SyntropyLog's marketing positioning is clear and powerful**:
233
+ #### **Environment-Based Configuration**
234
+ ```typescript
235
+ // config/syntropylog.ts
236
+ export const getSyntropyConfig = (env: string) => {
237
+ const baseConfig = {
238
+ logger: {
239
+ level: process.env.LOG_LEVEL || 'info',
240
+ serviceName: process.env.SERVICE_NAME,
241
+ },
242
+ context: {
243
+ correlationIdHeader: 'X-Correlation-ID',
244
+ }
245
+ };
171
246
 
172
- > **SyntropyLog is the observability orchestration framework for high-performance teams. Get distributed tracing, resource management, and enterprise-level logging with zero measurable performance overhead and minimal application size impact.**
247
+ switch (env) {
248
+ case 'development':
249
+ return {
250
+ ...baseConfig,
251
+ redis: { instances: [{ instanceName: 'cache', url: 'redis://localhost:6379' }] }
252
+ };
253
+
254
+ case 'staging':
255
+ return {
256
+ ...baseConfig,
257
+ redis: { instances: [{ instanceName: 'cache', url: process.env.STAGING_REDIS_URL }] },
258
+ masking: { fields: ['password', 'token'] }
259
+ };
260
+
261
+ case 'production':
262
+ return {
263
+ ...baseConfig,
264
+ redis: { instances: [{ instanceName: 'cache', url: process.env.PROD_REDIS_URL }] },
265
+ masking: { fields: ['password', 'token', 'secret', 'apiKey'] },
266
+ loggingMatrix: {
267
+ default: ['correlationId', 'serviceName'],
268
+ error: ['*']
269
+ }
270
+ };
271
+ }
272
+ };
273
+ ```
173
274
 
174
- It's a tool that doesn't force developers to compromise speed for visibility, setting a new standard for what's possible in the Node.js ecosystem.
275
+ #### **Centralized Logging Infrastructure**
276
+ ```typescript
277
+ // shared/syntropylog-setup.ts
278
+ export class SyntropyLogManager {
279
+ private static instance: SyntropyLogManager;
280
+
281
+ static getInstance(): SyntropyLogManager {
282
+ if (!SyntropyLogManager.instance) {
283
+ SyntropyLogManager.instance = new SyntropyLogManager();
284
+ }
285
+ return SyntropyLogManager.instance;
286
+ }
175
287
 
176
- ## 🎭 Core Philosophy: Silent Observer
288
+ async initialize(serviceName: string) {
289
+ const config = getSyntropyConfig(process.env.NODE_ENV);
290
+ await syntropyLog.init({
291
+ ...config,
292
+ logger: { ...config.logger, serviceName }
293
+ });
294
+ }
177
295
 
178
- **SyntropyLog follows the "Silent Observer" principle - we report what happened and nothing more.**
296
+ getLogger(context?: string) {
297
+ return syntropyLog.getLogger(context);
298
+ }
299
+
300
+ getRedis(instanceName: string) {
301
+ return syntropyLog.getRedis(instanceName);
302
+ }
303
+ }
304
+ ```
179
305
 
180
- ### 🚫 Never Interrupts Your Application
306
+ ### **πŸ“Š Enterprise Monitoring Integration**
181
307
 
308
+ #### **Prometheus Metrics**
182
309
  ```typescript
183
- // βœ… Your application continues running, even if logging fails
184
- try {
185
- const result = await database.query('SELECT * FROM users');
186
- logger.info('Query successful', { count: result.length });
187
- } catch (error) {
188
- // Your error handling continues normally
189
- logger.error('Database error', { error: error.message });
190
- // Application logic continues...
191
- }
310
+ // Add custom metrics to your logs
311
+ const logger = syntropyLog.getLogger();
312
+ logger.info('API Request', {
313
+ endpoint: '/users',
314
+ method: 'GET',
315
+ duration: 150,
316
+ statusCode: 200,
317
+ // These will be automatically picked up by your monitoring system
318
+ metrics: {
319
+ request_duration_ms: 150,
320
+ requests_total: 1,
321
+ status_code: 200
322
+ }
323
+ });
192
324
  ```
193
325
 
194
- ### πŸ” What Happens When Logging Fails
326
+ #### **ELK Stack Integration**
327
+ ```typescript
328
+ // Configure for ELK stack
329
+ await syntropyLog.init({
330
+ logger: {
331
+ serviceName: 'user-service',
332
+ level: 'info',
333
+ transports: [
334
+ new JsonConsoleTransport(), // Structured JSON for Logstash
335
+ ]
336
+ },
337
+ context: {
338
+ correlationIdHeader: 'X-Correlation-ID',
339
+ }
340
+ });
341
+ ```
195
342
 
196
- 1. **Configuration Errors** β†’ Application fails to start (as expected)
197
- 2. **Pipeline Errors** β†’ Error reported to transports, application continues
198
- 3. **Serializer Errors** β†’ Error reported to transports, application continues
199
- 4. **Transport Errors** β†’ Error reported to console, application continues
343
+ ### **πŸ”’ Enterprise Security Features**
344
+
345
+ #### **Data Masking**
346
+ ```typescript
347
+ // Automatic sensitive data masking
348
+ await syntropyLog.init({
349
+ masking: {
350
+ fields: ['password', 'token', 'secret', 'apiKey', 'creditCard'],
351
+ preserveLength: true, // Shows **** instead of completely hiding
352
+ patterns: [
353
+ { regex: /\\b\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}\\b/, replacement: '[CARD_NUMBER]' }
354
+ ]
355
+ }
356
+ });
200
357
 
201
- ### πŸ“‘ Error Reporting Strategy
358
+ // Usage - sensitive data is automatically masked
359
+ logger.info('User login attempt', {
360
+ email: 'user@example.com',
361
+ password: 'secret123', // Will be masked as '********'
362
+ token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' // Will be masked
363
+ });
364
+ ```
202
365
 
366
+ #### **Compliance Logging**
203
367
  ```typescript
204
- // Any error in the logging pipeline:
205
- // 1. Reports to configured transports (console, file, etc.)
206
- // 2. Application continues running normally
207
- // 3. No exceptions thrown to your code
208
- // 4. No application interruption
209
-
210
- logger.info('This will work even if serialization fails');
211
- logger.error('This will work even if transport fails');
368
+ // GDPR/Compliance ready logging
369
+ await syntropyLog.init({
370
+ loggingMatrix: {
371
+ default: ['correlationId', 'serviceName', 'timestamp'],
372
+ audit: ['*'], // Log everything for audit trails
373
+ error: ['*', 'stackTrace', 'context'],
374
+ security: ['*', 'ipAddress', 'userAgent', 'requestId']
375
+ }
376
+ });
212
377
  ```
213
378
 
214
- **Think of SyntropyLog as a journalist - we observe, report, and never interfere with the main story.**
379
+ ---
215
380
 
216
- ## πŸ“š Documentation
381
+ ## πŸ“š Manual & Tutorials
217
382
 
218
- - **[Getting Started](https://syntropysoft.github.io/syntropylog-doc/docs/getting-started)** - Complete setup guide *(in progress)*
219
- - **[API Reference](https://syntropysoft.github.io/syntropylog-doc/docs/api-reference)** - Full API documentation *(in progress)*
220
- - **[Examples](https://syntropysoft.github.io/syntropylog-doc/examples)** - 30 production-ready examples *(in progress)*
221
- - **[Configuration Guide](https://syntropysoft.github.io/syntropylog-doc/docs/configuration)** - Advanced configuration *(in progress)*
383
+ ### **🎯 Getting Started Tutorials**
222
384
 
223
- ## 🎯 Production Ready
385
+ #### **Tutorial 1: Basic Logging (5 minutes)**
386
+ ```typescript
387
+ // 1. Install and initialize
388
+ import { syntropyLog } from 'syntropylog';
224
389
 
225
- SyntropyLog is **BETA (v0.7.1)** and ready for production use:
390
+ await syntropyLog.init({
391
+ logger: { serviceName: 'tutorial-app', level: 'info' }
392
+ });
226
393
 
227
- ### πŸ“ Version Notes
228
- **v0.7.1** - *Performance & Security Release*
229
- - ⚑ **Performance Excellence** - Identical performance to Pino (1.00x ratio) with advanced features
230
- - πŸ”’ **JSON Flattening MaskingEngine** - Ultra-fast data masking at any object depth with zero performance impact
231
- - πŸ›‘οΈ **Enhanced Security** - Hybrid masking strategy (field name + content pattern) with preserveLength option
232
- - πŸ“Š **Stable Benchmarks** - Consistent results across multiple benchmark runs
233
- - πŸ§ͺ **Comprehensive Testing** - 769 tests passing with 100% MaskingEngine test coverage
394
+ // 2. Use basic logging
395
+ const logger = syntropyLog.getLogger();
396
+ logger.info('Application started');
397
+ logger.warn('This is a warning');
398
+ logger.error('This is an error', { error: 'Something went wrong' });
234
399
 
235
- **v0.7.0** - *Enterprise Security Release*
236
- - πŸ”’ **Enterprise Security** - GitHub Dependabot, CodeQL static analysis, and automated vulnerability scanning
237
- - πŸ›‘οΈ **Branch Protection** - Complete CI/CD pipeline with status checks and quality gates
238
- - πŸ“Š **Enhanced Testing** - Improved test coverage (88.93%) with comprehensive test helpers
239
- - πŸ§ͺ **Testing Framework** - SyntropyLogMock, BeaconRedisMock, and test helpers for zero-boilerplate testing
240
- - πŸ“š **32 Complete Examples** - Including testing patterns, message brokers, and enterprise patterns
241
- - 🎯 **Production Ready** - Kubernetes-ready with singleton pattern and resource management
242
- - ⚑ **Zero External Dependencies** - No Redis, brokers, or HTTP servers needed for testing
400
+ // 3. Add context
401
+ logger.info('User action', { userId: '123', action: 'login' });
402
+ ```
243
403
 
244
- - βœ… **88.93% test coverage** across 769 tests
245
- - βœ… **Core features stable** - Logger, context, HTTP, Redis, brokers
246
- - βœ… **API stable** - Backward compatible
247
- - βœ… **32 examples complete** - Core features, message brokers, and testing patterns tested
248
- - βœ… **Real integration** - Examples work with actual services (Redis, Kafka, etc.)
404
+ #### **Tutorial 2: Context and Correlation (10 minutes)**
405
+ ```typescript
406
+ // 1. Set up context management
407
+ await syntropyLog.init({
408
+ logger: { serviceName: 'context-demo', level: 'info' },
409
+ context: { correlationIdHeader: 'X-Correlation-ID' }
410
+ });
249
411
 
250
- ## πŸ”§ Standard Configuration
412
+ // 2. Create context for a request
413
+ const contextManager = syntropyLog.getContextManager();
414
+ contextManager.run(async () => {
415
+ // Set correlation ID
416
+ contextManager.set('X-Correlation-ID', 'req-123');
417
+
418
+ const logger = syntropyLog.getLogger();
419
+ logger.info('Request started'); // Automatically includes correlation ID
420
+
421
+ // All operations in this context will have the same correlation ID
422
+ await someAsyncOperation();
423
+
424
+ logger.info('Request completed');
425
+ });
426
+ ```
427
+
428
+ #### **Tutorial 3: Redis Integration (15 minutes)**
429
+ ```typescript
430
+ // 1. Configure Redis
431
+ await syntropyLog.init({
432
+ logger: { serviceName: 'redis-demo', level: 'info' },
433
+ context: { correlationIdHeader: 'X-Correlation-ID' },
434
+ redis: {
435
+ instances: [{
436
+ instanceName: 'cache',
437
+ url: 'redis://localhost:6379'
438
+ }]
439
+ }
440
+ });
251
441
 
252
- For most applications, you'll want HTTP instrumentation and context management:
442
+ // 2. Use Redis with automatic correlation
443
+ const redis = syntropyLog.getRedis('cache');
444
+ const logger = syntropyLog.getLogger();
253
445
 
446
+ // Set context
447
+ const contextManager = syntropyLog.getContextManager();
448
+ contextManager.run(async () => {
449
+ contextManager.set('X-Correlation-ID', 'user-456');
450
+
451
+ // All operations automatically include correlation ID
452
+ await redis.set('user:456:profile', JSON.stringify({ name: 'John' }));
453
+ const profile = await redis.get('user:456:profile');
454
+
455
+ logger.info('User profile cached', { userId: '456' });
456
+ });
457
+ ```
458
+
459
+ ### **πŸ”§ Advanced Configuration Tutorials**
460
+
461
+ #### **Tutorial 4: Custom Transports (20 minutes)**
254
462
  ```typescript
255
- import { syntropyLog, PrettyConsoleTransport } from 'syntropylog';
256
- import { AxiosAdapter } from '@syntropylog/adapters';
257
- import axios from 'axios';
463
+ // 1. Create custom transport
464
+ import { Transport } from 'syntropylog';
465
+
466
+ class SlackTransport extends Transport {
467
+ async log(level: string, message: string, meta: any) {
468
+ if (level === 'error') {
469
+ // Send errors to Slack
470
+ await this.sendToSlack({
471
+ text: `🚨 Error in ${meta.serviceName}: ${message}`,
472
+ attachments: [{ text: JSON.stringify(meta, null, 2) }]
473
+ });
474
+ }
475
+ }
476
+ }
258
477
 
478
+ // 2. Use custom transport
259
479
  await syntropyLog.init({
260
480
  logger: {
481
+ serviceName: 'slack-demo',
261
482
  level: 'info',
262
- serviceName: 'my-app',
263
- transports: [new PrettyConsoleTransport()],
264
- },
265
- loggingMatrix: {
266
- default: ['correlationId'],
267
- error: ['*'], // Log everything on errors
268
- },
483
+ transports: [
484
+ new PrettyConsoleTransport(),
485
+ new SlackTransport()
486
+ ]
487
+ }
488
+ });
489
+ ```
490
+
491
+ #### **Tutorial 5: HTTP Client Integration (25 minutes)**
492
+ ```typescript
493
+ // 1. Configure HTTP client
494
+ import { AxiosAdapter } from '@syntropylog/adapters';
495
+ import axios from 'axios';
496
+
497
+ await syntropyLog.init({
498
+ logger: { serviceName: 'http-demo', level: 'info' },
499
+ context: { correlationIdHeader: 'X-Correlation-ID' },
269
500
  http: {
270
- instances: [
271
- {
272
- instanceName: 'myApi',
273
- adapter: new AxiosAdapter(axios.create({ baseURL: 'https://api.example.com' })),
274
- },
275
- ],
276
- },
501
+ instances: [{
502
+ instanceName: 'api',
503
+ adapter: new AxiosAdapter(axios.create({
504
+ baseURL: 'https://api.example.com'
505
+ }))
506
+ }]
507
+ }
277
508
  });
278
509
 
279
- // Use the instrumented client (singleton instances)
280
- const apiClient = syntropyLog.getHttp('myApi');
510
+ // 2. Use instrumented HTTP client
511
+ const apiClient = syntropyLog.getHttp('api');
281
512
  const logger = syntropyLog.getLogger();
282
513
 
283
- // Automatic correlation and logging
284
- await apiClient.request({ method: 'GET', url: '/users' });
285
-
286
- // Multiple instances with different configurations
287
- const userLogger = syntropyLog.getLogger('user-service');
288
- const paymentLogger = syntropyLog.getLogger('payment-service');
289
- const cacheRedis = syntropyLog.getRedis('cache');
290
- const sessionRedis = syntropyLog.getRedis('session');
291
- const eventsBroker = syntropyLog.getBroker('events');
292
- const notificationsBroker = syntropyLog.getBroker('notifications');
514
+ // All HTTP calls automatically include correlation ID and logging
515
+ const response = await apiClient.request({
516
+ method: 'GET',
517
+ url: '/users/123'
518
+ });
293
519
 
294
- // All instances are singletons - efficient resource usage
520
+ logger.info('API call completed', {
521
+ statusCode: response.status,
522
+ duration: response.duration
523
+ });
295
524
  ```
296
525
 
297
- ## πŸš€ Simple Example: Automatic Context Propagation
298
-
299
- **The magic of SyntropyLog: Configure once, get automatic context everywhere.**
300
-
301
- ### **🎯 What You'll Learn**
302
- - How to set up SyntropyLog in 30 seconds
303
- - How context (correlation IDs) automatically propagates to all operations
304
- - How to use it with Express.js and Fastify
305
- - How Redis operations automatically include the same correlation ID
526
+ #### **Tutorial 6: Auditing & Custom Adapters (30 minutes)**
527
+ ```typescript
528
+ // 1. Define a persistent adapter (e.g. for Postgres/Internal API)
529
+ import { ILogTransportAdapter, AdapterTransport, syntropyLog } from 'syntropylog';
306
530
 
307
- ### **πŸ“¦ 1. Simple Configuration**
531
+ class MyDatabaseAdapter implements ILogTransportAdapter {
532
+ async log(entry: any) {
533
+ // In a real app: await db.insert('audit_logs', entry);
534
+ console.log('Auditing to DB:', entry.message);
535
+ }
536
+ }
308
537
 
309
- ```typescript
310
- // Just configure what you need
538
+ // 2. Configure with category routing and audit level
311
539
  await syntropyLog.init({
312
- logger: { serviceName: 'my-app', level: 'info' },
313
- context: { correlationIdHeader: 'X-Correlation-ID' },
314
- redis: {
315
- instances: [{
316
- instanceName: 'cache',
317
- url: 'redis://localhost:6379'
318
- }]
540
+ logger: {
541
+ serviceName: 'secure-app',
542
+ level: 'info',
543
+ transports: {
544
+ default: [new ConsoleTransport()],
545
+ audit: [new AdapterTransport({ adapter: new MyDatabaseAdapter() })]
546
+ }
319
547
  }
320
548
  });
549
+
550
+ // 3. Usage: Audit logs bypass standard level filtering
551
+ const logger = syntropyLog.getLogger('audit');
552
+ await logger.audit('Sensitive User Action', { userId: '456' }); // Always persisted
321
553
  ```
322
554
 
323
- ### **πŸ”— 2. Framework Integration (Choose One)**
555
+ ### **πŸš€ Universal Persistence (Storage Agnostic)**
556
+ Starting from v0.8.x, SyntropyLog includes a powerful way to persist logs to any destination without external dependencies. By using `UniversalAdapter` and `UniversalLogFormatter`, you can map your logs to any schema using JSON and provide an execution function.
324
557
 
325
- #### **Express.js (Traditional)**
558
+ #### **The Quickest Example: In-memory/Console Capture**
326
559
  ```typescript
327
- // contextMiddleware.ts - Reusable for any Express app
328
- import { syntropyLog } from 'syntropylog';
560
+ const adapter = new UniversalAdapter({
561
+ executor: (data) => console.log('Captured by Adapter:', data)
562
+ });
329
563
 
330
- export function syntropyContextMiddleware() {
331
- return (req, res, next) => {
332
- const contextManager = syntropyLog.getContextManager();
333
-
334
- contextManager.run(async () => {
335
- // Get correlation ID from header OR generate one automatically
336
- const correlationId = req.headers['x-correlation-id'] || contextManager.getCorrelationId();
337
- contextManager.set('X-Correlation-ID', correlationId);
338
- next();
339
- });
340
- };
341
- }
564
+ const formatter = new UniversalLogFormatter({
565
+ mapping: { msg: 'message', severity: 'level' }
566
+ });
342
567
 
343
- // Use it in your Express app
344
- app.use(syntropyContextMiddleware());
568
+ // Result: { msg: "Hello", severity: "info" }
345
569
  ```
346
570
 
347
- #### **Fastify (High Performance)**
571
+ #### **Example: Persisting to MongoDB (Object-based)**
348
572
  ```typescript
349
- // ProductServer.ts - Fastify with automatic context
350
- import Fastify from 'fastify';
351
- import { syntropyLog } from 'syntropylog';
573
+ import { UniversalAdapter, UniversalLogFormatter, syntropyLog } from 'syntropylog';
574
+
575
+ const mongoAdapter = new UniversalAdapter({
576
+ executor: (doc) => db.collection('logs').insertOne(doc)
577
+ });
352
578
 
353
- export class ProductServer {
354
- constructor() {
355
- this.app = Fastify();
356
- this.setupMiddleware();
579
+ const mongoFormatter = new UniversalLogFormatter({
580
+ mapping: {
581
+ user: 'metadata.userId',
582
+ event: 'message',
583
+ level: 'level',
584
+ payload: 'bindings' // Full object path
357
585
  }
586
+ });
358
587
 
359
- private setupMiddleware() {
360
- // Simple middleware - sets context for each request
361
- this.app.addHook('preHandler', async (request, reply) => {
362
- const contextManager = syntropyLog.getContextManager();
363
-
364
- // Extract correlation ID from headers or generate one
365
- const correlationId = request.headers['x-correlation-id'] || `fastify-${uuidv4()}`;
366
-
367
- // Set context - this will be available to all operations
368
- contextManager.set('X-Correlation-ID', correlationId);
369
- contextManager.set('requestId', request.id);
370
- contextManager.set('method', request.method);
371
- contextManager.set('url', request.url);
372
- });
588
+ await syntropyLog.init({
589
+ logger: {
590
+ transports: {
591
+ audit: [new AdapterTransport({
592
+ adapter: mongoAdapter,
593
+ formatter: mongoFormatter
594
+ })]
595
+ }
373
596
  }
374
- }
597
+ });
375
598
  ```
376
599
 
377
- ### **πŸͺ 3. Your Business Logic (Clean & Simple)**
378
-
600
+ #### **Example: Generic SQL (Postgres/MySQL)**
379
601
  ```typescript
380
- // ProductService.ts - Your normal business code
381
- export class ProductService {
382
- constructor() {
383
- this.redis = syntropyLog.getRedis('cache');
384
- this.logger = syntropyLog.getLogger();
385
- }
386
-
387
- async getProduct(id: string) {
388
- // Try cache first
389
- const cached = await this.redis.get(`product:${id}`);
390
- if (cached) {
391
- this.logger.info('Product found in cache', { id });
392
- return JSON.parse(cached);
393
- }
602
+ const sqlAdapter = new UniversalAdapter({
603
+ executor: ({ sql, values }) => pool.query(sql, values)
604
+ });
394
605
 
395
- // Get from database
396
- const product = await this.getFromDatabase(id);
397
- await this.redis.set(`product:${id}`, JSON.stringify(product), 30);
398
- this.logger.info('Product retrieved from database', { id });
399
-
400
- return product;
606
+ const sqlFormatter = new UniversalLogFormatter({
607
+ mapping: {
608
+ column_user: 'bindings.userId',
609
+ column_msg: 'message'
401
610
  }
402
- }
611
+ });
403
612
  ```
404
613
 
405
- ### **🎯 4. Magic: Automatic Context Everywhere**
614
+ ---
406
615
 
407
- **Every log automatically includes the same correlation ID:**
616
+ ## ✨ Key Features
408
617
 
409
- ```
410
- 2025-07-30 16:50:35 INFO [X-Correlation-ID="abc123"] Redis GET product:1 (2ms)
411
- 2025-07-30 16:50:35 INFO [X-Correlation-ID="abc123"] Product retrieved from database { id: '1' }
412
- 2025-07-30 16:50:35 INFO [X-Correlation-ID="abc123"] Redis SET product:1 (1ms)
413
- ```
618
+ ### **πŸ”„ Zero Boilerplate**
619
+ - Get started in 30 seconds with automatic context propagation
620
+ - No complex setup or configuration required
621
+ - Works out of the box with sensible defaults
414
622
 
415
- ### **✨ What You Get Automatically:**
623
+ ### **πŸ”— Automatic Correlation**
624
+ - Distributed tracing across services, HTTP calls, and message brokers
625
+ - Correlation IDs automatically propagate through all operations
626
+ - Complete request flow visibility without manual effort
416
627
 
417
- - βœ… **Same correlation ID** in all logs (Redis + your code)
418
- - βœ… **Performance tracking** for all operations
419
- - βœ… **Request context** (method, URL, request ID)
420
- - βœ… **Zero manual work** - just use the framework normally
421
- - βœ… **Framework agnostic** - works with Express, Fastify, Koa, etc.
628
+ ### **🎯 Framework Agnostic**
629
+ - Works with Express, Fastify, Koa, NestJS, and any Node.js app
630
+ - No framework-specific dependencies
631
+ - Easy integration with existing applications
422
632
 
423
- ### **πŸš€ Ready for More?**
633
+ ### **πŸ›‘οΈ Security First**
634
+ - Built-in data masking for sensitive information
635
+ - Compliance-ready logging with retention rules
636
+ - No external telemetry or tracking
424
637
 
425
- Once you understand this basic pattern, you can add:
426
- - HTTP clients with automatic logging
427
- - Message brokers (Kafka, RabbitMQ)
428
- - Data masking for security
429
- - Custom logging matrices
430
- - And much more...
638
+ ### **⚑ High Performance**
639
+ - 45,000+ ops/sec with less than 1ms latency
640
+ - Zero measurable performance overhead
641
+ - Minimal bundle size impact
431
642
 
432
- **Next steps:**
433
- 1. **Example 00** - Basic setup and logging
434
- 2. **Example 12** - Complete Express + Redis integration
435
- 3. **Example 13** - High-performance Fastify with automatic context
643
+ ### **πŸ—οΈ Singleton Pattern**
644
+ - Prevents pod crashes by managing resource instances efficiently
645
+ - Automatic connection pooling and resource management
646
+ - Kubernetes-ready with proper lifecycle management
436
647
 
437
- ## πŸ—οΈ Singleton Pattern - Intelligent Resource Management
648
+ ---
438
649
 
439
- SyntropyLog implements a **Singleton pattern** across all resource types, providing automatic instance management and preventing common production issues:
650
+ ## πŸ“Š Performance & Benchmarks
440
651
 
441
- ### **🎯 Named Instance Management**
442
- SyntropyLog uses different patterns for different resource types:
652
+ **SyntropyLog achieves a remarkable technical milestone: offering advanced distributed tracing and instance management capabilities with zero performance impact.**
443
653
 
444
- #### **πŸ“ Loggers - On-Demand Creation with Singleton Management**
445
- Loggers are the **only resources created on-demand** and managed as singletons:
654
+ ### **πŸ† Benchmark Results**
446
655
 
447
- ```typescript
448
- // Loggers - Created on-demand with automatic singleton management
449
- const userLogger = syntropyLog.getLogger('user-service'); // Creates new instance
450
- const paymentLogger = syntropyLog.getLogger('payment-service'); // Creates new instance
451
- const userLogger2 = syntropyLog.getLogger('user-service'); // Returns existing instance
452
-
453
- // Logger derivatives - Create specialized loggers from templates
454
- const userErrorLogger = syntropyLog.getLogger('user-service:errors'); // New instance
455
- const userDebugLogger = syntropyLog.getLogger('user-service:debug'); // New instance
456
-
457
- // Memory efficient - Only creates what you request
458
- // If you create 200 loggers, you get exactly 200 logger instances
459
- // No more, no less - controlled resource allocation
460
- ```
656
+ | Logger | Bundle Size (JS) | Performance Time | vs No Logger | vs Pino |
657
+ |--------|------------------|------------------|--------------|---------|
658
+ | No Logger | 5 KB | 3 ms | - | - |
659
+ | Pino | 5 KB | 2 ms | -193 B | - |
660
+ | **SyntropyLog** | **5 KB** | **2 ms** | **+10 B** | **+203 B (1.03x) / +0 ms (1.00x)** |
461
661
 
462
- #### **πŸ”— Infrastructure Resources - Pre-configured Singletons**
463
- Redis, brokers, and HTTP clients are **pre-configured in init()** and reused:
662
+ ### **πŸš€ Key Achievements**
663
+
664
+ 1. **Zero Performance Overhead** - Identical performance to Pino
665
+ 2. **Minimal Bundle Size** - Only 203 bytes larger than Pino
666
+ 3. **Advanced Features** - Distributed tracing, resource management, data masking
667
+ 4. **Enterprise Ready** - Security and compliance features included
668
+
669
+ ---
670
+
671
+ ## 🎭 Core Philosophy: Silent Observer
672
+
673
+ **SyntropyLog follows the "Silent Observer" principle - we report what happened and nothing more.**
674
+
675
+ ### **🚫 Never Interrupts Your Application**
464
676
 
465
677
  ```typescript
466
- // These instances are created during init() and reused
467
- const cacheRedis = syntropyLog.getRedis('cache'); // Returns pre-configured instance
468
- const sessionRedis = syntropyLog.getRedis('session'); // Returns pre-configured instance
469
- const eventsBroker = syntropyLog.getBroker('events'); // Returns pre-configured instance
470
- const apiClient = syntropyLog.getHttp('myApi'); // Returns pre-configured instance
471
-
472
- // All calls return the SAME pre-configured instances
473
- console.log(userLogger === userLogger2); // true βœ… (on-demand singleton)
474
- console.log(cacheRedis === cacheRedis); // true βœ… (pre-configured singleton)
475
- console.log(eventsBroker === eventsBroker); // true βœ… (pre-configured singleton)
476
- console.log(apiClient === apiClient); // true βœ… (pre-configured singleton)
678
+ // βœ… Your application continues running, even if logging fails
679
+ try {
680
+ const result = await database.query('SELECT * FROM users');
681
+ logger.info('Query successful', { count: result.length });
682
+ } catch (error) {
683
+ // Your error handling continues normally
684
+ logger.error('Database error', { error: error.message });
685
+ // Application logic continues...
686
+ }
477
687
  ```
478
688
 
479
- ### **πŸ”„ Automatic Resource Lifecycle**
480
- The framework manages resources differently based on their type:
689
+ ### **πŸ” Error Handling Strategy**
481
690
 
482
- #### **πŸ“ Logger Lifecycle (On-Demand)**
483
- - **First call**: Creates new logger instance and stores it internally
484
- - **Subsequent calls**: Returns the existing logger instance (singleton)
485
- - **Controlled allocation**: Only creates loggers you explicitly request
486
- - **Memory efficient**: If you create 200 loggers, you get exactly 200 instances
691
+ 1. **Configuration Errors** β†’ Application fails to start (as expected)
692
+ 2. **Pipeline Errors** β†’ Error reported to transports, application continues
693
+ 3. **Serializer Errors** β†’ Error reported to transports, application continues
694
+ 4. **Transport Errors** β†’ Error reported to console, application continues
487
695
 
488
- #### **πŸ”— Infrastructure Lifecycle (Pre-configured)**
489
- - **During init()**: Creates Redis, broker, and HTTP instances based on configuration
490
- - **Runtime calls**: Returns pre-configured instances (no new creation)
491
- - **Connection pooling**: Reuses existing connections efficiently
492
- - **Consistent state**: Same instances across your entire application
696
+ **Think of SyntropyLog as a journalist - we observe, report, and never interfere with the main story.**
493
697
 
494
- ### **⚑ Production Benefits**
495
- This pattern provides critical advantages in production environments:
698
+ ---
496
699
 
497
- - **πŸ›‘οΈ Pod Stability**: Prevents OOM (Out of Memory) crashes from multiple instances
498
- - **πŸ”— Connection Efficiency**: Reuses existing connections instead of creating new ones
499
- - **πŸ“Š Consistent Observability**: Same logger instance ensures consistent correlation IDs
500
- - **⚑ Performance**: Eliminates overhead of creating duplicate resources
501
- - **πŸ—οΈ Resource Management**: Automatic cleanup and connection pooling
502
- - **πŸš€ Kubernetes Ready**: Essential for containerized environments where memory is limited
700
+ ## πŸ”§ Configuration Guide
503
701
 
504
- ## πŸ§ͺ Testing Revolution
702
+ ### **Basic Configuration**
703
+ ```typescript
704
+ await syntropyLog.init({
705
+ logger: {
706
+ serviceName: 'my-app',
707
+ level: 'info', // debug, info, warn, error, audit
708
+ },
709
+ context: {
710
+ correlationIdHeader: 'X-Correlation-ID',
711
+ }
712
+ });
713
+ ```
505
714
 
506
- ### **🎯 Zero Boilerplate Testing with SyntropyLogMock**
715
+ ### **Advanced Configuration**
716
+ ```typescript
717
+ await syntropyLog.init({
718
+ logger: {
719
+ serviceName: 'my-app',
720
+ level: 'info',
721
+ transports: {
722
+ default: [new PrettyConsoleTransport()],
723
+ audit: [new MySecureTransport()]
724
+ }
725
+ },
726
+ context: {
727
+ correlationIdHeader: 'X-Correlation-ID',
728
+ traceIdHeader: 'X-Trace-ID',
729
+ },
730
+ redis: {
731
+ instances: [
732
+ { instanceName: 'cache', url: 'redis://localhost:6379' },
733
+ { instanceName: 'session', url: 'redis://localhost:6380' },
734
+ ]
735
+ },
736
+ brokers: {
737
+ instances: [
738
+ { instanceName: 'events', adapter: new KafkaAdapter(kafkaConfig) },
739
+ ]
740
+ },
741
+ http: {
742
+ instances: [
743
+ { instanceName: 'api', adapter: new AxiosAdapter(axiosConfig) },
744
+ ]
745
+ },
746
+ masking: {
747
+ fields: ['password', 'token', 'secret'],
748
+ preserveLength: true,
749
+ },
750
+ loggingMatrix: {
751
+ default: ['correlationId', 'serviceName'],
752
+ error: ['*'],
753
+ audit: ['*'],
754
+ }
755
+ });
756
+ ```
507
757
 
508
- Testing SyntropyLog applications is now **dramatically simplified** with our new testing framework:
758
+ ---
759
+
760
+ ## πŸ§ͺ Testing Guide
761
+
762
+ ### **Zero Boilerplate Testing**
509
763
 
510
764
  ```typescript
511
765
  import { describe, it, expect, beforeEach } from 'vitest';
@@ -524,47 +778,51 @@ describe('UserService', () => {
524
778
  });
525
779
 
526
780
  it('should create user successfully', async () => {
527
- const result = await userService.createUser({ name: 'John', email: 'john@example.com' });
781
+ const result = await userService.createUser({
782
+ name: 'John',
783
+ email: 'john@example.com'
784
+ });
528
785
  expect(result).toHaveProperty('userId');
529
786
  expect(result.name).toBe('John');
530
787
  });
531
788
  });
532
789
  ```
533
790
 
534
- ### **πŸš€ What's New in v0.7.0**
535
-
536
- - **πŸ”’ Enterprise Security** - GitHub Dependabot, CodeQL static analysis, and automated vulnerability scanning
537
- - **πŸ›‘οΈ Branch Protection** - Complete CI/CD pipeline with status checks and quality gates
538
- - **πŸ“Š Enhanced Testing** - Improved test coverage (88.93%) with comprehensive test helpers
539
- - **πŸ§ͺ Testing Framework** - SyntropyLogMock, BeaconRedisMock, and test helpers for zero-boilerplate testing
540
- - **πŸ“š 32 Complete Examples** - Including testing patterns, message brokers, and enterprise patterns
541
- - **🎯 Production Ready** - Kubernetes-ready with singleton pattern and resource management
542
- - **⚑ Zero External Dependencies** - No Redis, brokers, or HTTP servers needed for testing
543
-
544
- ### **βœ… Benefits**
545
-
791
+ ### **Benefits**
546
792
  - **🚫 No Connection Boilerplate** - No init/shutdown in tests
547
793
  - **⚑ Lightning Fast** - Everything runs in memory
548
794
  - **πŸ”’ Reliable** - No network issues or state conflicts
549
795
  - **🎯 Focused** - Test business logic, not framework internals
550
- - **πŸ”„ Framework Agnostic** - Works with Vitest, Jest, and any test runner
551
-
552
- [View Testing Examples β†’](https://syntropysoft.github.io/syntropylog-doc/docs/examples/28-testing-patterns-vitest)
553
-
554
- ## πŸ“¦ Ecosystem
555
-
556
- - **[syntropylog](https://www.npmjs.com/package/syntropylog)** - Core framework
557
- - **[@syntropylog/adapters](https://www.npmjs.com/package/@syntropylog/adapters)** - HTTP and broker adapters
558
- - **[@syntropylog/types](https://www.npmjs.com/package/@syntropylog/types)** - TypeScript types
559
- - **[syntropylog-examples](https://github.com/Syntropysoft/syntropylog-examples)** - 32 complete examples
560
-
561
- ## πŸš€ Examples
562
-
563
- Complete examples demonstrating SyntropyLog features:
564
796
 
565
- ### βœ… **Complete & Tested (00-15, 20-24, 28-32)**
797
+ ---
566
798
 
567
- #### **🎯 Beginner Friendly (00-09)**
799
+ ## πŸ“¦ Examples & Ecosystem
800
+
801
+ ### **πŸ”₯ Ejemplos que "Revientan por los Aires"**
802
+
803
+ Estos ejemplos demuestran el poder real de SyntropyLog en aplicaciones complejas del mundo real:
804
+
805
+ #### **πŸš€ [Microservicio Completo](./examples/01-microservice-complete/)**
806
+ **E-commerce API con observabilidad total**
807
+ - βœ… **Distributed tracing** automΓ‘tico entre servicios
808
+ - βœ… **Cache inteligente** con Redis y correlation IDs
809
+ - βœ… **HTTP clients instrumentados** para APIs externas
810
+ - βœ… **Data masking automΓ‘tico** para datos sensibles
811
+ - βœ… **Event streaming** con message brokers
812
+ - βœ… **Performance tracking** en todas las operaciones
813
+ - βœ… **Error handling robusto** con context preservation
814
+
815
+ #### **πŸ”₯ [Eventos en Tiempo Real](./examples/02-realtime-events/)**
816
+ **WebSocket server con analytics en tiempo real**
817
+ - βœ… **WebSocket management** con observabilidad automΓ‘tica
818
+ - βœ… **Real-time analytics** y mΓ©tricas de performance
819
+ - βœ… **Connection pooling** y room management
820
+ - βœ… **Event processing pipeline** con Redis persistence
821
+ - βœ… **Load balancing** y automatic error recovery
822
+ - βœ… **Security** con rate limiting y data masking
823
+ - βœ… **Production-ready** con Kubernetes deployment
824
+
825
+ ### **🎯 Ejemplos BÑsicos (00-09)**
568
826
  - **00**: Basic Setup - Simple initialization and logging
569
827
  - **01**: Configuration - Environment-based configuration
570
828
  - **02**: Context Management - Correlation IDs and request tracking
@@ -578,11 +836,11 @@ Complete examples demonstrating SyntropyLog features:
578
836
 
579
837
  #### **🌐 HTTP Framework Integration (10-15)**
580
838
  - **10**: Express.js - Traditional Express server with context
581
- - **11**: Koa.js - Modern Koa server with middleware
582
- - **12**: Express + Redis + Axios - Complete microservice with caching *(Reviewed and Fixed)*
583
- - **13**: Fastify + Redis - High-performance Fastify with automatic context propagation *(Reviewed and Fixed)*
839
+ - **11**: Custom HTTP Adapter - Creating custom adapters
840
+ - **12**: Express + Redis + Axios - Complete microservice with caching
841
+ - **13**: Fastify + Redis - High-performance Fastify with automatic context
584
842
  - **14**: NestJS Integration - Enterprise-grade framework with decorators
585
- - **15**: Hapi.js Integration - Enterprise server with plugin architecture
843
+ - **15**: Koa + Redis - Modern Koa server with Redis caching
586
844
 
587
845
  #### **πŸ“‘ Message Brokers (20-24)**
588
846
  - **20**: Kafka Integration - Event streaming with correlation
@@ -598,43 +856,117 @@ Complete examples demonstrating SyntropyLog features:
598
856
  - **31**: Serializer Testing - Custom serializer validation
599
857
  - **32**: Transport Spies - Testing log outputs and formats
600
858
 
601
- ### 🚧 **In Development (16-19, 25-27)**
602
- - **16-19**: Advanced Framework Features - Custom serializers, advanced patterns
603
- - **25-27**: Enterprise Patterns - Production configuration, advanced context
859
+ Estos ejemplos demuestran el poder real de SyntropyLog en aplicaciones complejas del mundo real:
860
+
861
+ #### **πŸš€ [Microservicio Completo](./examples/01-microservice-complete/)**
862
+ **E-commerce API con observabilidad total**
863
+ - βœ… **Distributed tracing** automΓ‘tico entre servicios
864
+ - βœ… **Cache inteligente** con Redis y correlation IDs
865
+ - βœ… **HTTP clients instrumentados** para APIs externas
866
+ - βœ… **Data masking automΓ‘tico** para datos sensibles
867
+ - βœ… **Event streaming** con message brokers
868
+ - βœ… **Performance tracking** en todas las operaciones
869
+ - βœ… **Error handling robusto** con context preservation
870
+
871
+ #### **πŸ”₯ [Eventos en Tiempo Real](./examples/02-realtime-events/)**
872
+ **WebSocket server con analytics en tiempo real**
873
+ - βœ… **WebSocket management** con observabilidad automΓ‘tica
874
+ - βœ… **Real-time analytics** y mΓ©tricas de performance
875
+ - βœ… **Connection pooling** y room management
876
+ - βœ… **Event processing pipeline** con Redis persistence
877
+ - βœ… **Load balancing** y automatic error recovery
878
+ - βœ… **Security** con rate limiting y data masking
879
+ - βœ… **Production-ready** con Kubernetes deployment
880
+
881
+ ### **πŸ“¦ Ecosystem**
882
+
883
+ - **[syntropylog](https://www.npmjs.com/package/syntropylog)** - Core framework
884
+ - **[@syntropylog/adapters](https://www.npmjs.com/package/@syntropylog/adapters)** - HTTP and broker adapters
885
+ - **[@syntropylog/types](https://www.npmjs.com/package/@syntropylog/types)** - TypeScript types
886
+ - **[syntropylog-examples](https://github.com/Syntropysoft/syntropylog-examples)** - 32 complete examples
604
887
 
605
- ### **🎯 Quick Start Examples**
888
+ ---
606
889
 
607
- **For beginners, start with:**
608
- 1. **Example 00** - Basic setup and logging
609
- 2. **Example 02** - Understanding context and correlation IDs
610
- 3. **Example 12** - Real-world Express + Redis integration
611
- 4. **Example 13** - High-performance Fastify with automatic context
890
+ ## πŸ”’ Security & Transparency
612
891
 
613
- **For HTTP frameworks:**
614
- - **Express.js**: Examples 10, 12
615
- - **Fastify**: Example 13 (recommended for performance)
616
- - **Koa.js**: Example 11
892
+ **We invite any member of the community to audit the code. If you find anything suspicious, please open an issue or a pull request.**
617
893
 
618
- **For testing:**
619
- - **Vitest**: Example 28 (recommended)
620
- - **Jest**: Example 29
894
+ ### **πŸ”’ Security Features**
895
+ - 100% open source and public
896
+ - No hidden telemetry, tracking, or obfuscated code
897
+ - Automated dependency and vulnerability scans via GitHub Dependabot and CodeQL
898
+ - High code coverage and comprehensive testing
899
+ - External and community audits are welcome
621
900
 
622
- [View all examples β†’](https://github.com/Syntropysoft/syntropylog-examples)
901
+ ### **🏒 Enterprise Security**
902
+ - Built-in data masking for sensitive information
903
+ - Compliance-ready logging with retention rules
904
+ - GDPR and SOC2 compliance features
905
+ - No external data transmission
906
+
907
+ ---
623
908
 
624
909
  ## 🀝 Contributing
625
910
 
626
911
  We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
627
912
 
913
+ ### **🎯 How to Contribute**
914
+ 1. Fork the repository
915
+ 2. Create a feature branch
916
+ 3. Make your changes
917
+ 4. Add tests for new functionality
918
+ 5. Submit a pull request
919
+
920
+ ### **πŸ”§ Development Setup**
921
+ ```bash
922
+ git clone https://github.com/Syntropysoft/SyntropyLog.git
923
+ cd SyntropyLog
924
+ npm install
925
+ npm run test
926
+ ```
927
+
928
+ ---
929
+
628
930
  ## πŸ“„ License
629
931
 
630
932
  This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
631
933
 
632
- ## πŸ“ž Support
934
+ ---
633
935
 
634
- - πŸ“– [Documentation](https://syntropysoft.github.io/syntropylog-doc/) *(in progress)*
635
- - πŸ› [Issues](https://github.com/Syntropysoft/SyntropyLog/issues)
636
- - πŸ’¬ [Discussions](https://github.com/Syntropysoft/SyntropyLog/discussions)
936
+ **From Chaos to Clarity** - Ship resilient, secure, and cost-effective Node.js applications with confidence.
637
937
 
638
938
  ---
639
939
 
640
- **From Chaos to Clarity** - Ship resilient, secure, and cost-effective Node.js applications with confidence.
940
+ ## πŸ‘¨β€πŸ’» Author & Contact
941
+
942
+ <p align="center">
943
+ <strong>Built with ❀️ by the SyntropySoft Team</strong>
944
+ </p>
945
+
946
+ ### **🀝 Get in Touch**
947
+ - **πŸ‘¨β€πŸ’Ό Gabriel Alejandro Gomez** - Lead Developer & Architect
948
+ - **πŸ’Ό [LinkedIn](https://www.linkedin.com/in/gabriel-alejandro-gomez-652a5111/)** - Connect for enterprise partnerships
949
+ - **πŸ“§ [Email](mailto:gabriel70@gmail.com)** - Technical questions & support
950
+ - **🏒 [SyntropySoft](https://syntropysoft.com)** - Enterprise solutions & consulting
951
+
952
+ ### **πŸ’Ό Enterprise Partnerships**
953
+ We specialize in enterprise observability solutions and custom integrations. Whether you need:
954
+ - **Custom transport development** for your existing APM stack
955
+ - **Enterprise deployment** and configuration
956
+ - **Performance optimization** and scaling strategies
957
+ - **Compliance implementation** (GDPR, SOC2, HIPAA)
958
+
959
+ **Let's discuss how SyntropyLog can enhance your observability strategy.**
960
+
961
+ ---
962
+
963
+ <p align="center">
964
+ <em>Empowering high-performance teams with enterprise-grade observability</em>
965
+ </p>
966
+
967
+ ---
968
+
969
+ <p align="center">
970
+ <strong>Thank you for considering SyntropyLog for your mission-critical systems.</strong><br>
971
+ <em>– Gabriel</em>
972
+ </p>