@mks2508/better-logger 0.18.3 → 0.18.4
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/dist/Logger.d.ts +0 -18
- package/dist/Logger.d.ts.map +1 -1
- package/dist/chunks/{LogContext-Dyzs61XG.js → LogContext-BO-f0KXu.js} +20 -14
- package/dist/chunks/{LogContext-Dyzs61XG.js.map → LogContext-BO-f0KXu.js.map} +1 -1
- package/dist/chunks/{LogContext-DZasm_P5.cjs → LogContext-CIKxWPrK.cjs} +20 -14
- package/dist/chunks/{LogContext-DZasm_P5.cjs.map → LogContext-CIKxWPrK.cjs.map} +1 -1
- package/dist/context/LogContext.d.ts.map +1 -1
- package/dist/context.cjs +1 -1
- package/dist/context.js +1 -1
- package/dist/index.cjs +25 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -35
- package/dist/index.js.map +1 -1
- package/dist/transports/SpanRuntime.d.ts +3 -0
- package/dist/transports/SpanRuntime.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/LogContext-BaMXleWj.cjs +0 -105
- package/dist/chunks/LogContext-BaMXleWj.cjs.map +0 -1
- package/dist/chunks/LogContext-DjlITOzZ.js +0 -100
- package/dist/chunks/LogContext-DjlITOzZ.js.map +0 -1
- package/dist/chunks/transports-BGfwwakw.js +0 -1237
- package/dist/chunks/transports-BGfwwakw.js.map +0 -1
- package/dist/chunks/transports-yK6CL0Ml.cjs +0 -1278
- package/dist/chunks/transports-yK6CL0Ml.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as resolveAsyncLocalStorage, t as createLogContext } from "./chunks/LogContext-
|
|
1
|
+
import { n as resolveAsyncLocalStorage, t as createLogContext } from "./chunks/LogContext-BO-f0KXu.js";
|
|
2
2
|
import { t as LOG_LEVELS } from "./chunks/core-Blfi2klP.js";
|
|
3
3
|
import { c as LOG_LEVEL_TO_SEVERITY_TEXT, s as LOG_LEVEL_TO_SEVERITY_NUMBER, t as TransportManager } from "./chunks/transports-DvaLAeGJ.js";
|
|
4
4
|
import { _ as DEFAULT_CONFIG, a as safeSerialize, b as parseStackTrace, c as ansiBackground, d as ansiDim, f as ansiStyle, g as CLI_LEVEL_MAP, h as formatSuccessANSI, i as getConsoleMethod, l as ansiBold, m as formatLogLevelANSI, o as createStyledOutput, p as ansiUnderline, r as formatTablePlain, s as setupThemeChangeListener, t as createLogEntry, u as ansiColor, y as formatTimestamp } from "./chunks/utils-tKfBAWUM.js";
|
|
@@ -1562,19 +1562,38 @@ function createTransportBridge() {
|
|
|
1562
1562
|
}
|
|
1563
1563
|
//#endregion
|
|
1564
1564
|
//#region src/transports/SpanRuntime.ts
|
|
1565
|
-
/**
|
|
1565
|
+
/**
|
|
1566
|
+
* ALS singleton del módulo — compartido por todas las instancias de Logger.
|
|
1566
1567
|
*
|
|
1567
1568
|
* Resolución por capas (global → `process.getBuiltinModule` → `require`,
|
|
1568
1569
|
* undefined en browser) delegada al helper compartido
|
|
1569
1570
|
* {@link resolveAsyncLocalStorage} — ver su doc para el detalle de capas.
|
|
1570
|
-
* `context/LogContext.ts` usa el mismo helper para su ALS de MDC.
|
|
1571
|
-
|
|
1571
|
+
* `context/LogContext.ts` usa el mismo helper para su ALS de MDC.
|
|
1572
|
+
*
|
|
1573
|
+
* Se crea lazy en el primer `runWithActiveSpan`: cargar `node:async_hooks`
|
|
1574
|
+
* cuesta ~2,2 MB de RSS en bun, y `getActiveSpan` se consulta en cada
|
|
1575
|
+
* dispatch de log — resolverlo al importar se lo cobraría a todo proceso
|
|
1576
|
+
* que loguea, use spans o no.
|
|
1577
|
+
*/
|
|
1578
|
+
let activeSpanStore;
|
|
1579
|
+
let spanStoreActivated = false;
|
|
1580
|
+
function activateSpanStore() {
|
|
1581
|
+
if (!spanStoreActivated) {
|
|
1582
|
+
spanStoreActivated = true;
|
|
1583
|
+
activeSpanStore = resolveAsyncLocalStorage();
|
|
1584
|
+
}
|
|
1585
|
+
return activeSpanStore;
|
|
1586
|
+
}
|
|
1572
1587
|
/**
|
|
1573
1588
|
* Span activo en el call stack corriente (dentro de `span(fn)`), si lo hay.
|
|
1574
1589
|
* Lo consumen la correlación log→span (`TransportRecord.traceId/spanId`) y la
|
|
1575
1590
|
* resolución de `parentSpanId` en spans hijos.
|
|
1591
|
+
*
|
|
1592
|
+
* Sin `run()` previo el store estaría vacío igual, así que el guard por
|
|
1593
|
+
* flag es observable-identico a consultar el ALS real.
|
|
1576
1594
|
*/
|
|
1577
1595
|
function getActiveSpan() {
|
|
1596
|
+
if (!spanStoreActivated) return void 0;
|
|
1578
1597
|
return activeSpanStore?.getStore();
|
|
1579
1598
|
}
|
|
1580
1599
|
/**
|
|
@@ -1582,7 +1601,8 @@ function getActiveSpan() {
|
|
|
1582
1601
|
* ejecuta `fn` directamente — sin correlación pero funcional.
|
|
1583
1602
|
*/
|
|
1584
1603
|
function runWithActiveSpan(record, fn) {
|
|
1585
|
-
|
|
1604
|
+
const store = activateSpanStore();
|
|
1605
|
+
return store ? store.run(record, fn) : fn();
|
|
1586
1606
|
}
|
|
1587
1607
|
/** Nanosegundos Unix actuales como string decimal (formato OTLP). */
|
|
1588
1608
|
function nowUnixNano() {
|
|
@@ -2666,36 +2686,6 @@ var Logger = class Logger {
|
|
|
2666
2686
|
* @internal
|
|
2667
2687
|
*/
|
|
2668
2688
|
_dispatchTag;
|
|
2669
|
-
/**
|
|
2670
|
-
* Computa el contexto completamente mergueado para este logger.
|
|
2671
|
-
*
|
|
2672
|
-
* La cadena de contexto se construye en el momento de crear el child:
|
|
2673
|
-
* cada child almacena el contexto fully-merged de su parent (en ese
|
|
2674
|
-
* instante) como `_parentContextRecord`. Esto implica que
|
|
2675
|
-
* `_parentContextRecord` ya contiene los bindings de todos los ancestros
|
|
2676
|
-
* en el orden de precedencia correcto (root primero, child más cercano al final).
|
|
2677
|
-
*
|
|
2678
|
-
* Orden de merge (gana el último):
|
|
2679
|
-
* 1. _parentContextRecord — snapshot del contexto mergueado del parent en la creación
|
|
2680
|
-
* 2. _bindings — bindings propios de este logger (llamadas a `child()`)
|
|
2681
|
-
* 3. ALS store — scope de `withContext`/`withContextAsync` (prioridad máxima)
|
|
2682
|
-
*
|
|
2683
|
-
* @internal
|
|
2684
|
-
* @returns El record de contexto mergueado
|
|
2685
|
-
*/
|
|
2686
|
-
_getMergedContext() {
|
|
2687
|
-
let merged = this._parentContextRecord ?? {};
|
|
2688
|
-
if (this._bindings && Object.keys(this._bindings).length > 0) merged = {
|
|
2689
|
-
...merged,
|
|
2690
|
-
...this._bindings
|
|
2691
|
-
};
|
|
2692
|
-
const alsContext = this.logContext._getAlsStore?.() ?? {};
|
|
2693
|
-
if (alsContext && Object.keys(alsContext).length > 0) merged = {
|
|
2694
|
-
...merged,
|
|
2695
|
-
...alsContext
|
|
2696
|
-
};
|
|
2697
|
-
return merged;
|
|
2698
|
-
}
|
|
2699
2689
|
/** @internal Expone el contexto base mergueado (sin ALS) a la closure de la child factory de LogContext. */
|
|
2700
2690
|
_captureMergedContext() {
|
|
2701
2691
|
let merged = this._parentContextRecord ?? {};
|