syntropylog 0.11.3 → 0.12.1
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.
- package/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +2 -0
- package/README.md +151 -20
- package/dist/index.cjs +1355 -1073
- package/dist/index.d.ts +307 -186
- package/dist/index.mjs +1305 -1057
- package/dist/testing/index.d.ts +5 -0
- package/dist/types/SyntropyLog.d.ts +11 -1
- package/dist/types/config.schema.d.ts +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/logger/LoggerFactory.d.ts +27 -4
- package/dist/types/logger/transports/BaseConsolePrettyTransport.d.ts +5 -2
- package/dist/types/logger/transports/Transport.d.ts +5 -0
- package/dist/types/logger/transports/optionalChalk.d.ts +6 -2
- package/dist/types/masking/MaskingEngine.d.ts +10 -0
- package/dist/types/sensitiveKeys.d.ts +76 -0
- package/dist/types/serialization/SerializationManager.d.ts +2 -0
- package/dist/types/type-exports.d.ts +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
First release after 0.11.3. Includes all framework refinements validated end-to-end with the examples repo (0.11.4 was never published to npm).
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- **Sonar:** Configuration and documentation for SonarQube/SonarCloud integration: exceptions for secret rules (S2068), consumer guides (EN/ES), and project properties. Improves code quality and deployment in pipelines using Sonar.
|
|
10
|
+
- **Docs and release:** Release preparation guide (`docs/PREPARAR_PUBLICACION.md`), linked from CONTRIBUTING. Minor documentation and repo consistency improvements.
|
|
11
|
+
- **Sensitive key aliases:** New `src/sensitiveKeys.ts` with constants (`MASK_KEY_PWD`, `MASK_KEY_TOK`, `MASK_KEY_SEC`, etc.) so the rest of the codebase does not use string literals that Sonar or other tools flag. `MaskingEngine`, `DataSanitizer`, `SerializationManager`, and `sanitizeConfig` use these aliases; only `sensitiveKeys.ts` contains the literal words. All aliases are exported from the package for consumers.
|
|
12
|
+
- **Masking: spread default rules and add your own:** New `getDefaultMaskingRules(options?)` and export of `MaskingStrategy`, `MaskingRule`, `GetDefaultMaskingRulesOptions`. Users can do `rules: [...getDefaultMaskingRules({ maskChar: '*' }), ...myRules]` and set `enableDefaultRules: false` when providing the full list. Default rules are built from the same aliases.
|
|
13
|
+
- **Sonar:** `sonar-project.properties` added: exclusion of `sensitiveKeys.ts`, and `sonar.issue.ignore.multicriteria` for rule S2068 (hardcoded secrets) on `src/masking/**` and `src/serialization/**` so deploy is not blocked. Docs added for consumers: how to add a Sonar exception for a file with their own sensitive words (EN: `docs/SONAR_FILE_EXCEPTION.md`, ES: `doc-es/SONAR_EXCEPCION_ARCHIVO.md`).
|
|
14
|
+
- **Docs:** README section 4 (MaskingEngine) expanded: spread default rules, full table of exported sensitive key aliases, Sonar exception summary. New `docs/SENSITIVE_KEY_ALIASES.md` with the full list of `MASK_KEY_*` constants. Documentation section links to Sensitive key aliases and Sonar exception. Reconfiguration in runtime (hot): new README section clarifying that only log level and additive masking rules are reconfigurable without restart.
|
|
15
|
+
- **Init pattern:** README section 9 (Per-call transport control) and Quick Start now show the correct init pattern (wait for `ready`/`error` before `getLogger()`); `serializerTimeoutMs` and `serviceName` included in examples.
|
|
16
|
+
- **Lint:** SerializationManager: replaced `(logEntry as any)` with `Record<string, unknown>`; removed unused destructuring variables in native serialize path (use copy + delete for metadata).
|
|
17
|
+
- **Examples repo:** Full refresh: main set 01–17 only, updated README and test script, self-contained benchmark (17-benchmark), removed obsolete scripts and optional folders.
|
|
18
|
+
|
|
19
|
+
## 0.12.1
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- **Security / env:** The package no longer reads any environment variables (addresses tooling such as Socket.dev). Use config/options instead: `logger.disableNativeAddon: true` in `init()` to disable the native addon (replaces `SYNTROPYLOG_NATIVE_DISABLE=1`). For console transports, pass `disableColors: true` or derive from `NO_COLOR` in your app to disable ANSI colors. See SECURITY.md.
|
|
24
|
+
|
|
3
25
|
## 0.11.3
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/CONTRIBUTING.md
CHANGED
|
@@ -88,6 +88,8 @@ We welcome code contributions! To contribute code, please follow these steps:
|
|
|
88
88
|
|
|
89
89
|
## Release process (maintainers)
|
|
90
90
|
|
|
91
|
+
Guía detallada: [docs/PREPARAR_PUBLICACION.md](docs/PREPARAR_PUBLICACION.md).
|
|
92
|
+
|
|
91
93
|
**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
94
|
|
|
93
95
|
**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).
|
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.11.
|
|
20
|
+
<a href="#"><img src="https://img.shields.io/badge/status-v0.11.4-brightgreen.svg" alt="Version 0.11.4"></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
|
|
|
@@ -52,7 +52,7 @@ Everything below is part of the same stack (benchmarks use this full stack). Eac
|
|
|
52
52
|
| 13 | **Matrix in runtime** | `reconfigureLoggingMatrix()` without restart; only field visibility, not security. |
|
|
53
53
|
| 14 | **Tree-shaking** | `sideEffects: false` + ESM; bundle only what you import. |
|
|
54
54
|
|
|
55
|
-
**More detail and examples (ES)
|
|
55
|
+
**More detail and examples:** this README (English). [Also in Spanish (ES): features and examples](doc-es/caracteristicas-y-ejemplos.md).
|
|
56
56
|
|
|
57
57
|
---
|
|
58
58
|
|
|
@@ -126,7 +126,7 @@ if (syntropyLog.isNativeAddonInUse()) {
|
|
|
126
126
|
}
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
To build the native addon from source, see [doc-es/building-native-addon.es.md](doc-es/building-native-addon.es.md) (Spanish).
|
|
130
130
|
|
|
131
131
|
---
|
|
132
132
|
|
|
@@ -216,6 +216,54 @@ await syntropyLog.init({
|
|
|
216
216
|
});
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
+
### Spread default rules and add your own
|
|
220
|
+
|
|
221
|
+
You can use the default rules and add more in one go: pass `getDefaultMaskingRules({ maskChar: '*', preserveLength: true })` and spread your custom rules. Set `enableDefaultRules: false` when you provide the full list yourself.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { getDefaultMaskingRules, MaskingStrategy } from 'syntropylog';
|
|
225
|
+
|
|
226
|
+
masking: {
|
|
227
|
+
enableDefaultRules: false,
|
|
228
|
+
maskChar: '*',
|
|
229
|
+
rules: [
|
|
230
|
+
...getDefaultMaskingRules({ maskChar: '*' }),
|
|
231
|
+
{ pattern: /myCustomKey|internalSecret/i, strategy: MaskingStrategy.PASSWORD },
|
|
232
|
+
],
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Sensitive key aliases: use `maskEnum`
|
|
237
|
+
|
|
238
|
+
The library exports a **single object `maskEnum`** with all sensitive key aliases and grouped arrays. Import it once and pick or spread what you need—no string literals (Sonar-safe), and no listing every constant.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { maskEnum, MaskingStrategy, getDefaultMaskingRules } from 'syntropylog';
|
|
242
|
+
|
|
243
|
+
masking: {
|
|
244
|
+
enableDefaultRules: false,
|
|
245
|
+
maskChar: '*',
|
|
246
|
+
rules: [
|
|
247
|
+
...getDefaultMaskingRules({ maskChar: '*' }),
|
|
248
|
+
// One pattern for all token-like keys (access_token, refresh_token, api_key, jwt, …)
|
|
249
|
+
{ pattern: new RegExp(maskEnum.MASK_KEYS_TOKEN.join('|'), 'i'), strategy: MaskingStrategy.TOKEN },
|
|
250
|
+
// Or pick a few
|
|
251
|
+
{ pattern: new RegExp([maskEnum.MASK_KEY_ACCESS_TOKEN, maskEnum.MASK_KEY_REFRESH_TOKEN].join('|'), 'i'), strategy: MaskingStrategy.TOKEN },
|
|
252
|
+
],
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
`maskEnum` includes every `MASK_KEY_*` (e.g. `MASK_KEY_PWD`, `MASK_KEY_ACCESS_TOKEN`) plus `MASK_KEYS_PASSWORD`, `MASK_KEYS_TOKEN`, and `MASK_KEYS_ALL`. Full list and alternatives: [docs/SENSITIVE_KEY_ALIASES.md](docs/SENSITIVE_KEY_ALIASES.md).
|
|
257
|
+
|
|
258
|
+
### Sonar exception for a file with your own words
|
|
259
|
+
|
|
260
|
+
If you have a file in your project where you define **your own** sensitive words or aliases (e.g. `mySensitiveKeys.ts`), Sonar may report secrets (e.g. S2068) there. You can add an exception so that file does not block the deploy:
|
|
261
|
+
|
|
262
|
+
- **Exclude the file from analysis:** in your `sonar-project.properties`, add it to `sonar.exclusions` (e.g. `sonar.exclusions=**/mySensitiveKeys.ts`).
|
|
263
|
+
- **Or ignore only rule S2068 on that file:** use `sonar.issue.ignore.multicriteria` with `ruleKey=typescript:S2068` and `resourceKey` set to that file’s path.
|
|
264
|
+
|
|
265
|
+
Full steps and examples: [docs/SONAR_FILE_EXCEPTION.md](docs/SONAR_FILE_EXCEPTION.md).
|
|
266
|
+
|
|
219
267
|
| Strategy | Example output |
|
|
220
268
|
|----------|----------------|
|
|
221
269
|
| PASSWORD | `********` |
|
|
@@ -311,22 +359,28 @@ auditLogger.info({ userId: 123, action: 'payment' }, 'Payment processed');
|
|
|
311
359
|
|
|
312
360
|
**What:** For a single log call you can send only to specific transports (`.override()`), add destinations (`.add()`), or remove one (`.remove()`), without creating new logger instances.
|
|
313
361
|
|
|
314
|
-
**How:** Define a transport pool with `transportList` and `env`, then use the fluent methods on the next call only:
|
|
362
|
+
**How:** Define a transport pool with `transportList` and `env`, then use the fluent methods on the next call only. Wait for `ready` before calling `getLogger()` (see [Quick Start](#init-and-first-log)):
|
|
315
363
|
|
|
316
364
|
```typescript
|
|
317
|
-
await
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
365
|
+
await new Promise<void>((resolve, reject) => {
|
|
366
|
+
syntropyLog.on('ready', () => resolve());
|
|
367
|
+
syntropyLog.on('error', (err) => reject(err));
|
|
368
|
+
syntropyLog.init({
|
|
369
|
+
logger: {
|
|
370
|
+
envKey: 'NODE_ENV',
|
|
371
|
+
serviceName: 'my-app',
|
|
372
|
+
serializerTimeoutMs: 100,
|
|
373
|
+
transportList: {
|
|
374
|
+
consola: new ColorfulConsoleTransport({ name: 'consola' }),
|
|
375
|
+
db: dbTransport,
|
|
376
|
+
azure: azureTransport,
|
|
377
|
+
},
|
|
378
|
+
env: {
|
|
379
|
+
development: ['consola'],
|
|
380
|
+
production: ['consola', 'db', 'azure'],
|
|
381
|
+
},
|
|
328
382
|
},
|
|
329
|
-
}
|
|
383
|
+
});
|
|
330
384
|
});
|
|
331
385
|
|
|
332
386
|
const log = syntropyLog.getLogger('app');
|
|
@@ -448,21 +502,98 @@ syntropyLog.init({
|
|
|
448
502
|
|
|
449
503
|
---
|
|
450
504
|
|
|
505
|
+
## Reconfiguration in runtime (hot)
|
|
506
|
+
|
|
507
|
+
**The only things you can reconfigure without restart are:**
|
|
508
|
+
|
|
509
|
+
1. **Log level** — e.g. raise to `debug` on a single POD for troubleshooting.
|
|
510
|
+
2. **Add masking rules** — add new rules so additional fields are redacted from logs.
|
|
511
|
+
3. **Transports (debug only)** — **only add** a console transport for developer clarity when someone has to review an error inside a POD. Existing transports are not removed; you add one (e.g. ColorfulConsoleTransport) so the developer sees output clearly. Only library console transports (Console, Pretty, Compact, Colorful, Classic); no AdapterTransport or custom. Call `resetTransports()` to remove the added one(s).
|
|
512
|
+
|
|
513
|
+
**Transports in hot (per POD — add one for visual debug; existing stay):**
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
import { syntropyLog, ColorfulConsoleTransport } from 'syntropylog';
|
|
517
|
+
|
|
518
|
+
// When a developer needs to review an error inside a POD: add a console transport (existing transports stay)
|
|
519
|
+
syntropyLog.reconfigureTransportsForDebug({
|
|
520
|
+
add: [new ColorfulConsoleTransport({ level: 'error' })],
|
|
521
|
+
});
|
|
522
|
+
// Later: remove the added transport(s)
|
|
523
|
+
syntropyLog.resetTransports();
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
Philosophy: only add console transports for visual help when debugging in a POD; existing transports are not removed. If you pass any other transport, the call throws.
|
|
527
|
+
|
|
528
|
+
**The library does not provide an HTTP endpoint.** Your backend should expose one (e.g. `POST /admin/reconfigure-logging`) so that, per POD or per service, you can apply the reconfigurations above. Supported body fields: `level`, `loggingMatrix`, `addTransportForDebug`, `addMaskingRules`, and **`resetTransports`** (set to `true` when done debugging to restore original transports and avoid extra logger overhead). Example with Express:
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
import express from 'express';
|
|
532
|
+
import { syntropyLog, ColorfulConsoleTransport, MaskingStrategy } from 'syntropylog';
|
|
533
|
+
|
|
534
|
+
const app = express();
|
|
535
|
+
app.use(express.json());
|
|
536
|
+
|
|
537
|
+
// Your endpoint: reconfigure everything that can be changed in hot
|
|
538
|
+
app.post('/admin/reconfigure-logging', (req, res) => {
|
|
539
|
+
try {
|
|
540
|
+
const { level, loggingMatrix, addTransportForDebug, addMaskingRules, resetTransports } = req.body ?? {};
|
|
541
|
+
|
|
542
|
+
if (level) {
|
|
543
|
+
const logger = syntropyLog.getLogger();
|
|
544
|
+
logger.setLevel(level);
|
|
545
|
+
}
|
|
546
|
+
if (loggingMatrix) syntropyLog.reconfigureLoggingMatrix(loggingMatrix);
|
|
547
|
+
if (addTransportForDebug === true) {
|
|
548
|
+
syntropyLog.reconfigureTransportsForDebug({ add: [new ColorfulConsoleTransport({ level: 'error' })] });
|
|
549
|
+
}
|
|
550
|
+
// Restore original transports when done debugging; avoids extra logger overhead
|
|
551
|
+
if (resetTransports === true) syntropyLog.resetTransports();
|
|
552
|
+
if (Array.isArray(addMaskingRules)) {
|
|
553
|
+
const masker = syntropyLog.getMasker();
|
|
554
|
+
for (const r of addMaskingRules) {
|
|
555
|
+
masker.addRule({ pattern: new RegExp(r.pattern, 'i'), strategy: r.strategy });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
res.json({ ok: true });
|
|
560
|
+
} catch (err) {
|
|
561
|
+
res.status(400).json({ error: err instanceof Error ? err.message : String(err) });
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
Secure this route (e.g. auth, internal only). When debugging in a POD is finished, send `resetTransports: true` so the added console transport is removed and everything is left as it was, avoiding extra logger overhead. Core masking config (`maskChar`, `maxDepth`), and the rest stay as set at `init()`.
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
451
570
|
## Security & Compliance
|
|
452
571
|
|
|
453
572
|
| Dynamically configurable | Fixed at init |
|
|
454
573
|
|--------------------------|---------------|
|
|
455
|
-
|
|
|
574
|
+
| Log level, additive masking rules, transports (debug: add console only for visual help in a POD; existing stay; `resetTransports()` to remove added) | Core masking config (`maskChar`, `maxDepth`), Redis/HTTP/broker |
|
|
456
575
|
|
|
457
576
|
---
|
|
458
577
|
|
|
459
578
|
## Documentation
|
|
460
579
|
|
|
461
|
-
|
|
580
|
+
**English (primary)**
|
|
581
|
+
|
|
582
|
+
- **This README** — Full picture, Quick Start, and a “How” section per feature (above).
|
|
583
|
+
- **[Examples repository](https://github.com/Syntropysoft/syntropylog-examples)** — Runnable examples 01–17: setup, context, transports, HTTP correlation, testing, benchmark.
|
|
584
|
+
- **[Transport pool and per-environment routing](examples/TRANSPORT_POOL_AND_ENV.md)** — `transportList`, `env`, override/add/remove; runnable [TransportPoolExample.ts](examples/TransportPoolExample.ts).
|
|
585
|
+
- **[Sensitive key aliases](docs/SENSITIVE_KEY_ALIASES.md)** — Recommended use of `maskEnum` (single object, declarative); full list of `MASK_KEY_*` and grouped arrays.
|
|
586
|
+
- **[Sonar: exception for a specific file](docs/SONAR_FILE_EXCEPTION.md)** — How to add a Sonar exception when you have your own file with sensitive words or aliases (so it does not block deploy).
|
|
587
|
+
- **[CONTRIBUTING.md](./CONTRIBUTING.md)** — How to contribute.
|
|
588
|
+
- **[SECURITY.md](./SECURITY.md)** — Security policy and environment variables.
|
|
589
|
+
|
|
590
|
+
**Spanish (ES)**
|
|
591
|
+
|
|
592
|
+
- **[Features and examples](doc-es/caracteristicas-y-ejemplos.md)** — Canonical stack list with explanations and code examples; aligned with the benchmark report.
|
|
462
593
|
- **[Benchmark report (throughput + memory)](doc-es/benchmark-memory-run.md)** — Run `pnpm run bench` or `pnpm run bench:memory` from repo root. Compare native vs JS: `pnpm run bench` vs `SYNTROPYLOG_NATIVE_DISABLE=1 pnpm run bench`.
|
|
463
|
-
- **[Rust addon
|
|
594
|
+
- **[Rust addon — build from source](doc-es/building-native-addon.es.md)**.
|
|
464
595
|
- **[Improvement plan & roadmap](doc-es/code-improvement-analysis-and-plan.md)** — Backlog and phased plan.
|
|
465
|
-
- **[Rust implementation plan
|
|
596
|
+
- **[Rust implementation plan](doc-es/rust-implementation-plan.md)** — Native addon checklist; links to [rust-pipeline-optimization.md](doc-es/rust-pipeline-optimization.md).
|
|
466
597
|
|
|
467
598
|
---
|
|
468
599
|
|