@mks2508/better-logger 2.1.0 → 3.1.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.
- package/.claude/settings.local.json +8 -1
- package/CHANGELOG.json +168 -1
- package/CHANGELOG.md +127 -0
- package/CLAUDE.md +14 -1
- package/README.md +111 -20
- package/dist/Logger.d.ts +217 -70
- package/dist/Logger.d.ts.map +1 -1
- package/dist/ScopedLogger.d.ts +23 -276
- package/dist/ScopedLogger.d.ts.map +1 -1
- package/dist/chunks/Logger-BV0v1AyC.js +2 -0
- package/dist/chunks/Logger-BV0v1AyC.js.map +1 -0
- package/dist/chunks/{Logger-B7L-ujY4.js → Logger-C086w3EM.js} +868 -102
- package/dist/chunks/Logger-C086w3EM.js.map +1 -0
- package/dist/chunks/environment-C_8J-zQ_.js +4 -0
- package/dist/chunks/environment-C_8J-zQ_.js.map +1 -0
- package/dist/chunks/{environment-TI2ByCPT.js → environment-DXHouGD4.js} +468 -100
- package/dist/chunks/environment-DXHouGD4.js.map +1 -0
- package/dist/chunks/{formatting-CuNUqGks.js → formatting-BNnVUPcw.js} +2 -2
- package/dist/chunks/{formatting-CuNUqGks.js.map → formatting-BNnVUPcw.js.map} +1 -1
- package/dist/chunks/{formatting-Blwy-f0W.js → formatting-Cg5YhB9Y.js} +2 -2
- package/dist/chunks/{formatting-Blwy-f0W.js.map → formatting-Cg5YhB9Y.js.map} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +2 -2
- package/dist/exports-module.d.ts +1 -1
- package/dist/exports-module.d.ts.map +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +2 -2
- package/dist/hooks/HookManager.d.ts +21 -0
- package/dist/hooks/HookManager.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +433 -20
- package/dist/index.js.map +1 -1
- package/dist/serializers/SerializerRegistry.d.ts +16 -0
- package/dist/serializers/SerializerRegistry.d.ts.map +1 -0
- package/dist/serializers/index.d.ts +2 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/styling/StyleCache.d.ts +42 -0
- package/dist/styling/StyleCache.d.ts.map +1 -0
- package/dist/styling-module.d.ts +1 -1
- package/dist/styling-module.d.ts.map +1 -1
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +3 -3
- package/dist/terminal/color-converter.d.ts +73 -0
- package/dist/terminal/color-converter.d.ts.map +1 -0
- package/dist/terminal/formatter.d.ts +20 -0
- package/dist/terminal/formatter.d.ts.map +1 -0
- package/dist/terminal/terminal-renderer.d.ts +20 -6
- package/dist/terminal/terminal-renderer.d.ts.map +1 -1
- package/dist/transports/ConsoleTransport.d.ts +9 -0
- package/dist/transports/ConsoleTransport.d.ts.map +1 -0
- package/dist/transports/FileTransport.d.ts +15 -0
- package/dist/transports/FileTransport.d.ts.map +1 -0
- package/dist/transports/HttpTransport.d.ts +16 -0
- package/dist/transports/HttpTransport.d.ts.map +1 -0
- package/dist/transports/TransportManager.d.ts +14 -0
- package/dist/transports/TransportManager.d.ts.map +1 -0
- package/dist/transports/index.d.ts +5 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/types/core.d.ts +55 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +36 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/serializers.d.ts +25 -0
- package/dist/types/serializers.d.ts.map +1 -0
- package/dist/types/transports.d.ts +47 -0
- package/dist/types/transports.d.ts.map +1 -0
- package/dist/utils/environment-detector.d.ts +10 -0
- package/dist/utils/environment-detector.d.ts.map +1 -1
- package/docs/API.md +227 -0
- package/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/styling/package.json +2 -2
- package/src/Logger.ts +403 -114
- package/src/ScopedLogger.ts +78 -318
- package/src/hooks/HookManager.ts +177 -0
- package/src/hooks/index.ts +1 -0
- package/src/index.ts +133 -3
- package/src/serializers/SerializerRegistry.ts +173 -0
- package/src/serializers/index.ts +1 -0
- package/src/styling/StyleCache.ts +131 -0
- package/src/terminal/color-converter.ts +315 -0
- package/src/terminal/formatter.ts +236 -0
- package/src/terminal/terminal-renderer.ts +74 -79
- package/src/transports/ConsoleTransport.ts +28 -0
- package/src/transports/FileTransport.ts +53 -0
- package/src/transports/HttpTransport.ts +56 -0
- package/src/transports/TransportManager.ts +130 -0
- package/src/transports/index.ts +4 -0
- package/src/types/core.ts +68 -0
- package/src/types/hooks.ts +45 -0
- package/src/types/index.ts +44 -1
- package/src/types/serializers.ts +30 -0
- package/src/types/transports.ts +52 -0
- package/src/utils/environment-detector.ts +23 -1
- package/dist/chunks/Logger-B7L-ujY4.js.map +0 -1
- package/dist/chunks/Logger-DzU_c5sX.js +0 -2
- package/dist/chunks/Logger-DzU_c5sX.js.map +0 -1
- package/dist/chunks/ScopedLogger-BY3-E8Ov.js +0 -2
- package/dist/chunks/ScopedLogger-BY3-E8Ov.js.map +0 -1
- package/dist/chunks/ScopedLogger-D-RbiFZn.js +0 -361
- package/dist/chunks/ScopedLogger-D-RbiFZn.js.map +0 -1
- package/dist/chunks/environment-Ba5kShbx.js +0 -4
- package/dist/chunks/environment-Ba5kShbx.js.map +0 -1
- package/dist/chunks/environment-TI2ByCPT.js.map +0 -1
|
@@ -29,7 +29,14 @@
|
|
|
29
29
|
"Bash(find:*)",
|
|
30
30
|
"Bash(npm run type-check:*)",
|
|
31
31
|
"Bash(git tag:*)",
|
|
32
|
-
"Bash(npx tsc:*)"
|
|
32
|
+
"Bash(npx tsc:*)",
|
|
33
|
+
"Bash(ls -la /Volumes/KODAK1TB/REPOS y PROYECTOS/nodejs/advanced-logger/dist/*.d.ts)",
|
|
34
|
+
"Bash(wc:*)",
|
|
35
|
+
"mcp__plugin_context7_context7__resolve-library-id",
|
|
36
|
+
"mcp__plugin_context7_context7__get-library-docs",
|
|
37
|
+
"WebFetch(domain:www.nearform.com)",
|
|
38
|
+
"Bash(grep:*)",
|
|
39
|
+
"Bash(cat:*)"
|
|
33
40
|
],
|
|
34
41
|
"deny": [],
|
|
35
42
|
"ask": [],
|
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,173 @@
|
|
|
1
1
|
{
|
|
2
|
-
"current_version": "0.
|
|
2
|
+
"current_version": "0.16.0-alpha.1",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.16.0-alpha.1",
|
|
6
|
+
"date": "2025-12-28",
|
|
7
|
+
"type": "minor",
|
|
8
|
+
"title": "Versión Alpha - Nuevas funcionalidades incluyendo Custom Serializers: `logger y 4 más",
|
|
9
|
+
"changes": [
|
|
10
|
+
{
|
|
11
|
+
"type": "improvement",
|
|
12
|
+
"title": "chore: release 0.15.0-alpha.1 [skip ci]",
|
|
13
|
+
"description": "chore: release 0.15.0-alpha.1 [skip ci]"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "improvement",
|
|
17
|
+
"title": "Update package.json",
|
|
18
|
+
"description": "Update package.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "feature",
|
|
22
|
+
"title": "Custom Serializers: `logger",
|
|
23
|
+
"description": "Custom Serializers: `logger.addSerializer(Error, fn)` para transformar objetos"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"type": "feature",
|
|
27
|
+
"title": "Hooks System: `logger",
|
|
28
|
+
"description": "Hooks System: `logger.on('beforeLog', fn)` para interceptar logs"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"type": "feature",
|
|
32
|
+
"title": "Middleware: `logger",
|
|
33
|
+
"description": "Middleware: `logger.use((entry, next) => {...})` pipeline de procesamiento"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"type": "feature",
|
|
37
|
+
"title": "Transports: `logger",
|
|
38
|
+
"description": "Transports: `logger.addTransport({target: 'file'})` para file/http/custom destinations"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "feature",
|
|
42
|
+
"title": "Badges: `logger",
|
|
43
|
+
"description": "Badges: `logger.badges(['v3']).info()` sistema de etiquetado flexible"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"type": "improvement",
|
|
47
|
+
"title": "~50-100x menos memoria en child loggers (delegación vs herencia)",
|
|
48
|
+
"description": "~50-100x menos memoria en child loggers (delegación vs herencia)"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"type": "improvement",
|
|
52
|
+
"title": "Style Cache con LRU + TTL para estilos computados",
|
|
53
|
+
"description": "Style Cache con LRU + TTL para estilos computados"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"type": "improvement",
|
|
57
|
+
"title": "Serialización automática con detección de tipos",
|
|
58
|
+
"description": "Serialización automática con detección de tipos"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"type": "breaking",
|
|
62
|
+
"title": "ScopedLogger usa delegación (no herencia)",
|
|
63
|
+
"description": "ScopedLogger usa delegación (no herencia)"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"type": "breaking",
|
|
67
|
+
"title": "Métodos component/api/scope ahora síncronos",
|
|
68
|
+
"description": "Métodos component/api/scope ahora síncronos"
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"technical_notes": "Nuevos módulos enterprise:\n- SerializerRegistry (src/serializers/): serialización type-based con prioridad\n- HookManager (src/hooks/): sistema de hooks (beforeLog/afterLog/onError) y middleware pipeline\n- TransportManager + ConsoleTransport/FileTransport/HttpTransport (src/transports/)\n- StyleCache (src/styling/StyleCache.ts): cache LRU con TTL para estilos computados\n\nIntegración en Logger.ts:\n- Nuevas propiedades: serializerRegistry, hookManager, transportManager\n- Nuevos métodos: addSerializer(), removeSerializer(), on(), once(), off(), use()\n- Nuevos métodos transports: addTransport(), removeTransport(), flushTransports(), closeTransports()\n- Método log() modificado: serializa args, emite hooks, escribe a transports async\n\nTypes añadidos (src/types/):\n- serializers.ts: SerializerFn, SerializerContext, ISerializerRegistry\n- hooks.ts: HookLogEntry, HookEvent, HookCallback, MiddlewareFn, IHookManager\n- transports.ts: TransportRecord, TransportTarget, ITransport\n\nScopedLogger refactorizado: delegación en lugar de herencia (~50-100x menos memoria)",
|
|
72
|
+
"breaking_changes": [
|
|
73
|
+
"ScopedLogger usa delegación (no herencia)",
|
|
74
|
+
"Métodos component/api/scope ahora síncronos"
|
|
75
|
+
],
|
|
76
|
+
"commit_hash": "7a27ac9bfd84b56318b54ee37563eed404943e94",
|
|
77
|
+
"prefix": "alpha"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"version": "0.15.0-alpha.1",
|
|
81
|
+
"date": "2025-12-28",
|
|
82
|
+
"type": "minor",
|
|
83
|
+
"title": "Versión Alpha - Mejoras y optimizaciones",
|
|
84
|
+
"changes": [
|
|
85
|
+
{
|
|
86
|
+
"type": "improvement",
|
|
87
|
+
"title": "chore: release 0.14.0-alpha.1 [skip ci]",
|
|
88
|
+
"description": "chore: release 0.14.0-alpha.1 [skip ci]"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"type": "improvement",
|
|
92
|
+
"title": "**Colores ANSI completos** para terminales con 16 colores + estilos",
|
|
93
|
+
"description": "**Colores ANSI completos** para terminales con 16 colores + estilos"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"type": "improvement",
|
|
97
|
+
"title": "**Detección automática** de entorno Next",
|
|
98
|
+
"description": "**Detección automática** de entorno Next.js, Webpack, CI/CD"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"type": "improvement",
|
|
102
|
+
"title": "**Formateo inteligente** según capacidades del terminal",
|
|
103
|
+
"description": "**Formateo inteligente** según capacidades del terminal"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "improvement",
|
|
107
|
+
"title": "**Presets optimizados** para cada caso de uso",
|
|
108
|
+
"description": "**Presets optimizados** para cada caso de uso"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"type": "improvement",
|
|
112
|
+
"title": "`auto`: Detección automática del entorno óptimo",
|
|
113
|
+
"description": "`auto`: Detección automática del entorno óptimo"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"type": "improvement",
|
|
117
|
+
"title": "`ansi`: Colores ANSI para terminales modernos",
|
|
118
|
+
"description": "`ansi`: Colores ANSI para terminales modernos"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"type": "improvement",
|
|
122
|
+
"title": "`build`: Formato optimizado para builds (Next",
|
|
123
|
+
"description": "`build`: Formato optimizado para builds (Next.js/webpack)"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"type": "improvement",
|
|
127
|
+
"title": "`ci`: Formato simple para CI/CD sin emojis",
|
|
128
|
+
"description": "`ci`: Formato simple para CI/CD sin emojis"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"type": "improvement",
|
|
132
|
+
"title": "`plain`: Texto plano para máxima compatibilidad",
|
|
133
|
+
"description": "`plain`: Texto plano para máxima compatibilidad"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"type": "improvement",
|
|
137
|
+
"title": "Eliminadas dependencias circulares entre módulos",
|
|
138
|
+
"description": "Eliminadas dependencias circulares entre módulos"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"type": "improvement",
|
|
142
|
+
"title": "Imports directos para mejor tree-shaking",
|
|
143
|
+
"description": "Imports directos para mejor tree-shaking"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "improvement",
|
|
147
|
+
"title": "Bundle size optimizado",
|
|
148
|
+
"description": "Bundle size optimizado"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"type": "improvement",
|
|
152
|
+
"title": "Construcción sin warnings",
|
|
153
|
+
"description": "Construcción sin warnings"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"type": "improvement",
|
|
157
|
+
"title": "1.1.0",
|
|
158
|
+
"description": "1.1.0"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"type": "improvement",
|
|
162
|
+
"title": "w",
|
|
163
|
+
"description": "w"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"technical_notes": "- Implementa sistema completo de colores ANSI para terminales Node.js\n- Agrega detección automática de entorno (Next.js, CI/CD, terminal)\n- Crea presets optimizados: nextjs, webpack, ci, terminal\n- Añade formatos de salida: auto, ansi, build, ci, plain\n- Soluciona dependencias circulares entre módulos utils\n- Mejora tree-shaking con imports directos específicos\n- Configuración automática basada en variables de entorno\n- Soporte para emojis con alternativas de texto para CI",
|
|
167
|
+
"breaking_changes": [],
|
|
168
|
+
"commit_hash": "7571e0cf9cfe9c7b4f19d7b525987f530229445b",
|
|
169
|
+
"prefix": "alpha"
|
|
170
|
+
},
|
|
4
171
|
{
|
|
5
172
|
"version": "0.14.0-alpha.1",
|
|
6
173
|
"date": "2025-09-08",
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,133 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.0.0] - 2024-12-28
|
|
9
|
+
|
|
10
|
+
### 💥 Breaking Changes
|
|
11
|
+
- `ScopedLogger` ya no hereda de `Logger` - usa delegación para ~50-100x menos memoria
|
|
12
|
+
- Métodos `component()`, `api()`, `scope()` ahora son síncronos (antes devolvían Promise)
|
|
13
|
+
- `LogEntry` de hooks renombrado a `HookLogEntry` para evitar conflicto con handlers
|
|
14
|
+
|
|
15
|
+
### ✨ Features
|
|
16
|
+
|
|
17
|
+
#### Custom Serializers
|
|
18
|
+
Sistema de serialización extensible para objetos personalizados:
|
|
19
|
+
```typescript
|
|
20
|
+
logger.addSerializer(Error, (err) => ({
|
|
21
|
+
name: err.name,
|
|
22
|
+
message: err.message,
|
|
23
|
+
stack: err.stack?.split('\n').slice(0, 5)
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
logger.addSerializer(User, (user) => ({
|
|
27
|
+
id: user.id,
|
|
28
|
+
email: user.email // password omitido por seguridad
|
|
29
|
+
}));
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Hooks & Middleware
|
|
33
|
+
Sistema de eventos y middleware para interceptar logs:
|
|
34
|
+
```typescript
|
|
35
|
+
// Hooks
|
|
36
|
+
logger.on('beforeLog', (entry) => {
|
|
37
|
+
entry.correlationId = getCorrelationId();
|
|
38
|
+
return entry;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
logger.on('afterLog', (entry) => {
|
|
42
|
+
metrics.increment(`logs.${entry.level}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Middleware
|
|
46
|
+
logger.use((entry, next) => {
|
|
47
|
+
entry.requestId = asyncLocalStorage.getStore()?.requestId;
|
|
48
|
+
next();
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Transports System
|
|
53
|
+
Sistema de transports similar a Pino para envío de logs:
|
|
54
|
+
```typescript
|
|
55
|
+
// File transport
|
|
56
|
+
logger.addTransport({
|
|
57
|
+
target: 'file',
|
|
58
|
+
options: { destination: '/var/log/app.log' }
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// HTTP transport con batching
|
|
62
|
+
logger.addTransport({
|
|
63
|
+
target: 'http',
|
|
64
|
+
options: {
|
|
65
|
+
url: 'https://logs.example.com',
|
|
66
|
+
batchSize: 100,
|
|
67
|
+
flushInterval: 5000
|
|
68
|
+
},
|
|
69
|
+
level: 'warn'
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Custom transport
|
|
73
|
+
logger.addTransport({
|
|
74
|
+
target: {
|
|
75
|
+
name: 'elasticsearch',
|
|
76
|
+
write: async (record) => {
|
|
77
|
+
await esClient.index({ index: 'logs', body: record });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Badges System
|
|
84
|
+
Sistema de badges para etiquetar logs:
|
|
85
|
+
```typescript
|
|
86
|
+
logger.badges(['v3', 'stable']).info('Release publicado');
|
|
87
|
+
logger.badge('DEBUG').info('Modo debug activo');
|
|
88
|
+
logger.clearBadges();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Interface Bindings
|
|
92
|
+
Nueva interfaz `Bindings` para contexto de logs:
|
|
93
|
+
```typescript
|
|
94
|
+
interface Bindings {
|
|
95
|
+
scope?: string;
|
|
96
|
+
badges?: string[];
|
|
97
|
+
context?: Record<string, any>;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 🚀 Performance
|
|
102
|
+
- **~50-100x menos memoria** en child loggers (delegación vs herencia)
|
|
103
|
+
- **~10-20x más rápido** creación de child loggers
|
|
104
|
+
- **Style Cache** con LRU y TTL para estilos computados
|
|
105
|
+
- Serialización automática con detección de tipos
|
|
106
|
+
|
|
107
|
+
### 📦 New Exports
|
|
108
|
+
```typescript
|
|
109
|
+
// Classes
|
|
110
|
+
export { SerializerRegistry, HookManager, TransportManager };
|
|
111
|
+
export { ConsoleTransport, FileTransport, HttpTransport };
|
|
112
|
+
export { StyleCache, getStyleCache };
|
|
113
|
+
|
|
114
|
+
// Types
|
|
115
|
+
export type { SerializerFn, SerializerContext, ISerializerRegistry };
|
|
116
|
+
export type { HookLogEntry, HookEvent, HookCallback, MiddlewareFn, IHookManager };
|
|
117
|
+
export type { TransportRecord, TransportTarget, ITransport, StyleCacheConfig };
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## [2.0.0] - 2024-12-20
|
|
123
|
+
|
|
124
|
+
### ✨ Features
|
|
125
|
+
- **ScopedLogger con delegación**: Arquitectura ligera sin herencia
|
|
126
|
+
- **Métodos síncronos**: `component()`, `api()`, `scope()` ya no son async
|
|
127
|
+
- **logWithBindings()**: Método para logging con contexto de bindings
|
|
128
|
+
|
|
129
|
+
### 🔧 Internal
|
|
130
|
+
- Refactorizado sistema de child loggers para mejor performance
|
|
131
|
+
- Reducido footprint de memoria en aplicaciones con muchos loggers
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
8
135
|
## [1.2.0] - 2024-10-28
|
|
9
136
|
|
|
10
137
|
### ✨ Added
|
package/CLAUDE.md
CHANGED
|
@@ -201,4 +201,17 @@ npm run test:workflows
|
|
|
201
201
|
### Environment Variables
|
|
202
202
|
- `GITHUB_ACTIONS=true`: Detects CI environment
|
|
203
203
|
- `RELEASE_WORKFLOW=true`: Activates release-specific conflict strategies
|
|
204
|
-
- `GITHUB_WORKFLOW`: Workflow name for logging and context
|
|
204
|
+
- `GITHUB_WORKFLOW`: Workflow name for logging and context
|
|
205
|
+
|
|
206
|
+
## Code Comments Policy
|
|
207
|
+
|
|
208
|
+
**NO agregar comentarios LLM-generated:**
|
|
209
|
+
- ❌ "estilo Pino", "like Pino", "inspired by X"
|
|
210
|
+
- ❌ "mejorado", "arreglado", "optimizado"
|
|
211
|
+
- ❌ Comentarios obvios que repiten el nombre de la función/interface
|
|
212
|
+
- ❌ "@since 3.0.0" o versiones en JSDoc (ya está en git history)
|
|
213
|
+
|
|
214
|
+
**SÍ agregar cuando sea necesario:**
|
|
215
|
+
- ✅ JSDoc técnico con @param, @returns, @example útiles
|
|
216
|
+
- ✅ Comentarios que explican el "por qué" no obvio
|
|
217
|
+
- ✅ TODO/FIXME con contexto específico
|
package/README.md
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
# 🚀 Better Logger
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Enterprise-grade console logger with custom serializers, hooks, transports, and beautiful styling**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@mks2508/better-logger)
|
|
6
6
|
[](https://bundlephobia.com/package/@mks2508/better-logger)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](https://github.com/MKS2508/advanced-logger/blob/main/LICENSE)
|
|
9
9
|
|
|
10
|
-
Transform your console logging experience with
|
|
10
|
+
Transform your console logging experience with enterprise features like Pino/Winston: custom serializers, hooks/middleware, and transports - all with beautiful styling and professional themes.
|
|
11
11
|
|
|
12
12
|
## ✨ Features
|
|
13
13
|
|
|
14
|
+
### Core Features
|
|
14
15
|
- 🚀 **Simplified API** - 80% less code for basic use cases
|
|
15
16
|
- 🎨 **Smart Presets** - Apply beautiful themes in one line: `logger.preset('cyberpunk')`
|
|
16
|
-
- 🏷️ **
|
|
17
|
+
- 🏷️ **Badges System** - Flexible tagging with `badges()` and `badge()`
|
|
17
18
|
- 🌗 **Adaptive Themes** - Automatic light/dark mode detection
|
|
18
|
-
- ⚡ **Context Logging** - Temporary scopes that auto-cleanup
|
|
19
|
-
- 🎛️ **Toggle Controls** - Show/hide elements with simple methods
|
|
20
|
-
- 📊 **Data Export** - CSV, JSON, XML export with filtering
|
|
21
|
-
- 💻 **Interactive CLI** - Built-in command interface
|
|
22
|
-
- 🔧 **Modular Architecture** - Import only what you need
|
|
23
19
|
- 🎯 **TypeScript First** - Complete type safety and IntelliSense
|
|
24
20
|
|
|
21
|
+
### Enterprise Features (v3.0.0)
|
|
22
|
+
- 🔄 **Custom Serializers** - Transform any object type for logging
|
|
23
|
+
- 🪝 **Hooks & Middleware** - Intercept and modify logs with `on()`, `use()`
|
|
24
|
+
- 📡 **Transports** - File, HTTP, and custom transport destinations
|
|
25
|
+
- ⚡ **High Performance** - ~50-100x less memory with delegation pattern
|
|
26
|
+
- 💾 **Style Cache** - LRU cache for computed styles
|
|
27
|
+
|
|
25
28
|
## 📦 Installation
|
|
26
29
|
|
|
27
30
|
### Full Package (Recommended)
|
|
@@ -77,27 +80,115 @@ logger.hideBadges();
|
|
|
77
80
|
|
|
78
81
|
### Component & API Logging
|
|
79
82
|
```javascript
|
|
80
|
-
// Scoped loggers with auto-badges
|
|
83
|
+
// Scoped loggers with auto-badges (sync, lightweight)
|
|
81
84
|
const auth = logger.component('UserAuth');
|
|
82
85
|
auth.info('Login attempt'); // [COMPONENT] [UserAuth] Login attempt
|
|
83
86
|
auth.success('User verified'); // [COMPONENT] [UserAuth] User verified
|
|
84
87
|
|
|
85
88
|
// API loggers with multiple badges
|
|
86
|
-
const api = logger.api('GraphQL')
|
|
87
|
-
api.warn('Query timeout');
|
|
88
|
-
api.auth('Invalid token'); // [API] [AUTH] [GraphQL] Invalid token
|
|
89
|
+
const api = logger.api('GraphQL');
|
|
90
|
+
api.badges(['SLOW', 'CACHE']).warn('Query timeout');
|
|
89
91
|
```
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
## 🔄 Enterprise Features (v3.0.0)
|
|
94
|
+
|
|
95
|
+
### Custom Serializers
|
|
96
|
+
Transform complex objects before logging:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// Register serializers for custom types
|
|
100
|
+
logger.addSerializer(Error, (err) => ({
|
|
101
|
+
name: err.name,
|
|
102
|
+
message: err.message,
|
|
103
|
+
stack: err.stack?.split('\n').slice(0, 5)
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
logger.addSerializer(User, (user) => ({
|
|
107
|
+
id: user.id,
|
|
108
|
+
email: user.email // password automatically omitted
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
// Now errors and users are serialized automatically
|
|
112
|
+
logger.error('Failed:', new Error('Connection timeout'));
|
|
113
|
+
logger.info('User login:', currentUser);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Hooks & Middleware
|
|
117
|
+
Intercept and modify logs:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// Add correlation ID to all logs
|
|
121
|
+
logger.on('beforeLog', (entry) => {
|
|
122
|
+
entry.correlationId = getCorrelationId();
|
|
123
|
+
return entry;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Track metrics after logging
|
|
127
|
+
logger.on('afterLog', (entry) => {
|
|
128
|
+
metrics.increment(`logs.${entry.level}`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Middleware pipeline
|
|
132
|
+
logger.use((entry, next) => {
|
|
133
|
+
entry.requestId = asyncLocalStorage.getStore()?.requestId;
|
|
134
|
+
next();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Redact sensitive data
|
|
138
|
+
logger.use((entry, next) => {
|
|
139
|
+
entry.message = entry.message.replace(/password=\S+/g, 'password=***');
|
|
140
|
+
next();
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Transports
|
|
145
|
+
Send logs to multiple destinations:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
// File transport (Node.js)
|
|
149
|
+
logger.addTransport({
|
|
150
|
+
target: 'file',
|
|
151
|
+
options: { destination: '/var/log/app.log' }
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// HTTP transport with batching
|
|
155
|
+
logger.addTransport({
|
|
156
|
+
target: 'http',
|
|
157
|
+
options: {
|
|
158
|
+
url: 'https://logs.example.com/ingest',
|
|
159
|
+
batchSize: 100,
|
|
160
|
+
flushInterval: 5000
|
|
161
|
+
},
|
|
162
|
+
level: 'warn' // Only warn and above
|
|
163
|
+
});
|
|
94
164
|
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
165
|
+
// Custom transport
|
|
166
|
+
logger.addTransport({
|
|
167
|
+
target: {
|
|
168
|
+
name: 'elasticsearch',
|
|
169
|
+
write: async (record) => {
|
|
170
|
+
await esClient.index({ index: 'logs', body: record });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
99
173
|
});
|
|
100
|
-
|
|
174
|
+
|
|
175
|
+
// Flush and close when shutting down
|
|
176
|
+
await logger.flushTransports();
|
|
177
|
+
await logger.closeTransports();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Badges System
|
|
181
|
+
Flexible tagging for logs:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Multiple badges
|
|
185
|
+
logger.badges(['v3', 'stable']).info('Release published');
|
|
186
|
+
|
|
187
|
+
// Chain badges
|
|
188
|
+
logger.badge('DEBUG').badge('AUTH').info('Token validated');
|
|
189
|
+
|
|
190
|
+
// Clear badges
|
|
191
|
+
logger.clearBadges().info('Clean log');
|
|
101
192
|
```
|
|
102
193
|
|
|
103
194
|
### Simple Customization
|