@beethovn/logging 1.0.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/LICENSE +21 -0
- package/README.md +506 -0
- package/dist/core/CorrelationContextManager.d.ts +83 -0
- package/dist/core/CorrelationContextManager.d.ts.map +1 -0
- package/dist/core/CorrelationContextManager.js +102 -0
- package/dist/core/CorrelationContextManager.js.map +1 -0
- package/dist/core/Logger.d.ts +105 -0
- package/dist/core/Logger.d.ts.map +1 -0
- package/dist/core/Logger.js +210 -0
- package/dist/core/Logger.js.map +1 -0
- package/dist/core/types.d.ts +73 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +20 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/transports/ConsoleTransport.d.ts +27 -0
- package/dist/transports/ConsoleTransport.d.ts.map +1 -0
- package/dist/transports/ConsoleTransport.js +85 -0
- package/dist/transports/ConsoleTransport.js.map +1 -0
- package/dist/transports/LogTransport.d.ts +16 -0
- package/dist/transports/LogTransport.d.ts.map +1 -0
- package/dist/transports/LogTransport.js +2 -0
- package/dist/transports/LogTransport.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CorrelationContextManager.js","sourceRoot":"","sources":["../../src/core/CorrelationContextManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAC5B,MAAM,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAc,CAAC;IAE7D;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,GAAG,CAAI,OAAmB,EAAE,EAAW;QAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,gBAAgB;QACrB,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,aAAa,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS;QACd,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW;QAChB,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,QAAQ,CAAC;IACrC,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,aAAa,CAAC,OAA4B;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,qBAAqB;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3D,OAAO,OAAO,SAAS,IAAI,MAAM,EAAE,CAAC;IACtC,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type BeethovnError } from '@beethovn/errors';
|
|
2
|
+
import { type LoggerConfig } from './types.js';
|
|
3
|
+
import type { LogTransport } from '../transports/LogTransport.js';
|
|
4
|
+
/**
|
|
5
|
+
* Structured logger with correlation tracking
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Structured JSON logging
|
|
9
|
+
* - Automatic correlation ID tracking
|
|
10
|
+
* - Integration with BeethovnError
|
|
11
|
+
* - Multiple log levels
|
|
12
|
+
* - Transport abstraction
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const logger = new Logger({
|
|
17
|
+
* level: LogLevel.INFO,
|
|
18
|
+
* service: 'payment-service',
|
|
19
|
+
* json: true,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* logger.info('Payment processed', { paymentId: '123', amount: 100 });
|
|
23
|
+
* logger.error('Payment failed', error, { paymentId: '123' });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class Logger {
|
|
27
|
+
private config;
|
|
28
|
+
private transports;
|
|
29
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
30
|
+
/**
|
|
31
|
+
* Add a transport for outputting logs
|
|
32
|
+
*
|
|
33
|
+
* @param transport - The transport to add
|
|
34
|
+
*/
|
|
35
|
+
addTransport(transport: LogTransport): void;
|
|
36
|
+
/**
|
|
37
|
+
* Log a debug message
|
|
38
|
+
*
|
|
39
|
+
* @param message - Log message
|
|
40
|
+
* @param metadata - Additional structured data
|
|
41
|
+
*/
|
|
42
|
+
debug(message: string, metadata?: Record<string, unknown>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Log an info message
|
|
45
|
+
*
|
|
46
|
+
* @param message - Log message
|
|
47
|
+
* @param metadata - Additional structured data
|
|
48
|
+
*/
|
|
49
|
+
info(message: string, metadata?: Record<string, unknown>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Log a warning message
|
|
52
|
+
*
|
|
53
|
+
* @param message - Log message
|
|
54
|
+
* @param metadata - Additional structured data
|
|
55
|
+
*/
|
|
56
|
+
warn(message: string, metadata?: Record<string, unknown>): void;
|
|
57
|
+
/**
|
|
58
|
+
* Log an error message
|
|
59
|
+
*
|
|
60
|
+
* @param message - Log message
|
|
61
|
+
* @param error - Error object (optional)
|
|
62
|
+
* @param metadata - Additional structured data
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* try {
|
|
67
|
+
* await operation();
|
|
68
|
+
* } catch (error: unknown) {
|
|
69
|
+
* const err = ErrorFactory.fromUnknown(error);
|
|
70
|
+
* logger.error('Operation failed', err, { operationId: '123' });
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
error(message: string, error?: BeethovnError | Error | unknown, metadata?: Record<string, unknown>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Core logging method
|
|
77
|
+
*
|
|
78
|
+
* @param level - Log level
|
|
79
|
+
* @param message - Log message
|
|
80
|
+
* @param metadata - Additional data
|
|
81
|
+
*/
|
|
82
|
+
private log;
|
|
83
|
+
/**
|
|
84
|
+
* Extract error details from various error types
|
|
85
|
+
*/
|
|
86
|
+
private extractErrorDetails;
|
|
87
|
+
/**
|
|
88
|
+
* Default console output (used when no transports configured)
|
|
89
|
+
*/
|
|
90
|
+
private defaultOutput;
|
|
91
|
+
/**
|
|
92
|
+
* Create a child logger with additional context
|
|
93
|
+
*
|
|
94
|
+
* @param context - Context to add to all logs
|
|
95
|
+
* @returns New logger instance with context
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const paymentLogger = logger.child({ service: 'payment-processor' });
|
|
100
|
+
* paymentLogger.info('Processing payment'); // includes service context
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
child(context: Partial<LoggerConfig>): Logger;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/core/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAA+C,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAsB;gBAE5B,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;IAU9C;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAI3C;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIhE;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CACH,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,aAAa,GAAG,KAAK,GAAG,OAAO,EACvC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,IAAI;IAQP;;;;;;OAMG;IACH,OAAO,CAAC,GAAG;IAkCX;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAmC3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAwBrB;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM;CAQ9C"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { isBeethovnError } from '@beethovn/errors';
|
|
2
|
+
import { LogLevel, LOG_LEVEL_PRIORITY } from './types.js';
|
|
3
|
+
import { CorrelationContextManager } from './CorrelationContextManager.js';
|
|
4
|
+
/**
|
|
5
|
+
* Structured logger with correlation tracking
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Structured JSON logging
|
|
9
|
+
* - Automatic correlation ID tracking
|
|
10
|
+
* - Integration with BeethovnError
|
|
11
|
+
* - Multiple log levels
|
|
12
|
+
* - Transport abstraction
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const logger = new Logger({
|
|
17
|
+
* level: LogLevel.INFO,
|
|
18
|
+
* service: 'payment-service',
|
|
19
|
+
* json: true,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* logger.info('Payment processed', { paymentId: '123', amount: 100 });
|
|
23
|
+
* logger.error('Payment failed', error, { paymentId: '123' });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class Logger {
|
|
27
|
+
config;
|
|
28
|
+
transports = [];
|
|
29
|
+
constructor(config = {}) {
|
|
30
|
+
this.config = {
|
|
31
|
+
level: config.level ?? LogLevel.INFO,
|
|
32
|
+
service: config.service ?? 'beethovn',
|
|
33
|
+
json: config.json ?? true,
|
|
34
|
+
timestamps: config.timestamps ?? true,
|
|
35
|
+
colorize: config.colorize ?? false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add a transport for outputting logs
|
|
40
|
+
*
|
|
41
|
+
* @param transport - The transport to add
|
|
42
|
+
*/
|
|
43
|
+
addTransport(transport) {
|
|
44
|
+
this.transports.push(transport);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Log a debug message
|
|
48
|
+
*
|
|
49
|
+
* @param message - Log message
|
|
50
|
+
* @param metadata - Additional structured data
|
|
51
|
+
*/
|
|
52
|
+
debug(message, metadata) {
|
|
53
|
+
this.log(LogLevel.DEBUG, message, metadata);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Log an info message
|
|
57
|
+
*
|
|
58
|
+
* @param message - Log message
|
|
59
|
+
* @param metadata - Additional structured data
|
|
60
|
+
*/
|
|
61
|
+
info(message, metadata) {
|
|
62
|
+
this.log(LogLevel.INFO, message, metadata);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Log a warning message
|
|
66
|
+
*
|
|
67
|
+
* @param message - Log message
|
|
68
|
+
* @param metadata - Additional structured data
|
|
69
|
+
*/
|
|
70
|
+
warn(message, metadata) {
|
|
71
|
+
this.log(LogLevel.WARN, message, metadata);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Log an error message
|
|
75
|
+
*
|
|
76
|
+
* @param message - Log message
|
|
77
|
+
* @param error - Error object (optional)
|
|
78
|
+
* @param metadata - Additional structured data
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* try {
|
|
83
|
+
* await operation();
|
|
84
|
+
* } catch (error: unknown) {
|
|
85
|
+
* const err = ErrorFactory.fromUnknown(error);
|
|
86
|
+
* logger.error('Operation failed', err, { operationId: '123' });
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
error(message, error, metadata) {
|
|
91
|
+
const errorDetails = this.extractErrorDetails(error);
|
|
92
|
+
this.log(LogLevel.ERROR, message, {
|
|
93
|
+
...metadata,
|
|
94
|
+
...(errorDetails && { error: errorDetails }),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Core logging method
|
|
99
|
+
*
|
|
100
|
+
* @param level - Log level
|
|
101
|
+
* @param message - Log message
|
|
102
|
+
* @param metadata - Additional data
|
|
103
|
+
*/
|
|
104
|
+
log(level, message, metadata) {
|
|
105
|
+
// Check if this level should be logged
|
|
106
|
+
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.config.level]) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Get correlation context
|
|
110
|
+
const context = CorrelationContextManager.getContext();
|
|
111
|
+
// Build log entry
|
|
112
|
+
const entry = {
|
|
113
|
+
timestamp: new Date().toISOString(),
|
|
114
|
+
level,
|
|
115
|
+
message,
|
|
116
|
+
service: this.config.service,
|
|
117
|
+
correlationId: context?.correlationId,
|
|
118
|
+
userId: context?.userId,
|
|
119
|
+
tenantId: context?.tenantId,
|
|
120
|
+
...(metadata && { metadata }),
|
|
121
|
+
};
|
|
122
|
+
// Output to transports
|
|
123
|
+
if (this.transports.length > 0) {
|
|
124
|
+
this.transports.forEach(transport => transport.log(entry));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Default: console output
|
|
128
|
+
this.defaultOutput(entry);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Extract error details from various error types
|
|
133
|
+
*/
|
|
134
|
+
extractErrorDetails(error) {
|
|
135
|
+
if (!error) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
// BeethovnError - use toJSON()
|
|
139
|
+
if (isBeethovnError(error)) {
|
|
140
|
+
const json = error.toJSON();
|
|
141
|
+
return {
|
|
142
|
+
name: json.name,
|
|
143
|
+
code: json.code,
|
|
144
|
+
message: json.message,
|
|
145
|
+
stack: json.stack,
|
|
146
|
+
metadata: json.metadata,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Standard Error
|
|
150
|
+
if (error instanceof Error) {
|
|
151
|
+
return {
|
|
152
|
+
name: error.name,
|
|
153
|
+
code: 'UNKNOWN_ERROR',
|
|
154
|
+
message: error.message,
|
|
155
|
+
stack: error.stack,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Unknown error type
|
|
159
|
+
return {
|
|
160
|
+
name: 'UnknownError',
|
|
161
|
+
code: 'UNKNOWN_ERROR',
|
|
162
|
+
message: String(error),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Default console output (used when no transports configured)
|
|
167
|
+
*/
|
|
168
|
+
defaultOutput(entry) {
|
|
169
|
+
if (this.config.json) {
|
|
170
|
+
console.log(JSON.stringify(entry));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const parts = [
|
|
174
|
+
entry.timestamp,
|
|
175
|
+
`[${entry.level.toUpperCase()}]`,
|
|
176
|
+
entry.service,
|
|
177
|
+
entry.correlationId && `(${entry.correlationId})`,
|
|
178
|
+
entry.message,
|
|
179
|
+
].filter(Boolean);
|
|
180
|
+
console.log(parts.join(' '));
|
|
181
|
+
if (entry.metadata) {
|
|
182
|
+
console.log(' Metadata:', entry.metadata);
|
|
183
|
+
}
|
|
184
|
+
if (entry.error) {
|
|
185
|
+
console.error(' Error:', entry.error);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Create a child logger with additional context
|
|
191
|
+
*
|
|
192
|
+
* @param context - Context to add to all logs
|
|
193
|
+
* @returns New logger instance with context
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const paymentLogger = logger.child({ service: 'payment-processor' });
|
|
198
|
+
* paymentLogger.info('Processing payment'); // includes service context
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
child(context) {
|
|
202
|
+
const childLogger = new Logger({
|
|
203
|
+
...this.config,
|
|
204
|
+
...context,
|
|
205
|
+
});
|
|
206
|
+
childLogger.transports = this.transports;
|
|
207
|
+
return childLogger;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/core/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAsB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAoC,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAG3E;;;;;;;;;;;;;;;;;;;;;GAqBG;AAC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C7C,CAAC;YAED,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAA8B;QAClC,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC;YAC7B,GAAG,IAAI,CAAC,MAAM;YACd,GAAG,OAAO;SACX,CAAC,CAAC;QACH,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACzC,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels supported by the logging system
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
DEBUG = "debug",
|
|
6
|
+
INFO = "info",
|
|
7
|
+
WARN = "warn",
|
|
8
|
+
ERROR = "error"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Numeric priority for log levels (higher = more severe)
|
|
12
|
+
*/
|
|
13
|
+
export declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
|
|
14
|
+
/**
|
|
15
|
+
* Structured log entry
|
|
16
|
+
*/
|
|
17
|
+
export interface LogEntry {
|
|
18
|
+
/** Timestamp in ISO 8601 format */
|
|
19
|
+
timestamp: string;
|
|
20
|
+
/** Log level */
|
|
21
|
+
level: LogLevel;
|
|
22
|
+
/** Log message */
|
|
23
|
+
message: string;
|
|
24
|
+
/** Service/application name */
|
|
25
|
+
service?: string;
|
|
26
|
+
/** Correlation ID for request tracking */
|
|
27
|
+
correlationId?: string;
|
|
28
|
+
/** User ID if available */
|
|
29
|
+
userId?: string;
|
|
30
|
+
/** Tenant ID if available */
|
|
31
|
+
tenantId?: string;
|
|
32
|
+
/** Additional structured metadata */
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
/** Error details if logging an error */
|
|
35
|
+
error?: {
|
|
36
|
+
name: string;
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
stack?: string;
|
|
40
|
+
metadata?: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Log context - carries information across async operations
|
|
45
|
+
*/
|
|
46
|
+
export interface LogContext {
|
|
47
|
+
/** Correlation ID for request tracking */
|
|
48
|
+
correlationId?: string;
|
|
49
|
+
/** User ID */
|
|
50
|
+
userId?: string;
|
|
51
|
+
/** Tenant ID */
|
|
52
|
+
tenantId?: string;
|
|
53
|
+
/** Service name */
|
|
54
|
+
service?: string;
|
|
55
|
+
/** Additional context data */
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Logger configuration
|
|
60
|
+
*/
|
|
61
|
+
export interface LoggerConfig {
|
|
62
|
+
/** Minimum log level to output */
|
|
63
|
+
level: LogLevel;
|
|
64
|
+
/** Service/application name */
|
|
65
|
+
service: string;
|
|
66
|
+
/** Whether to output JSON format */
|
|
67
|
+
json: boolean;
|
|
68
|
+
/** Whether to include timestamps */
|
|
69
|
+
timestamps: boolean;
|
|
70
|
+
/** Whether to colorize output (for console) */
|
|
71
|
+
colorize: boolean;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAKvD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;I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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels supported by the logging system
|
|
3
|
+
*/
|
|
4
|
+
export var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel["DEBUG"] = "debug";
|
|
7
|
+
LogLevel["INFO"] = "info";
|
|
8
|
+
LogLevel["WARN"] = "warn";
|
|
9
|
+
LogLevel["ERROR"] = "error";
|
|
10
|
+
})(LogLevel || (LogLevel = {}));
|
|
11
|
+
/**
|
|
12
|
+
* Numeric priority for log levels (higher = more severe)
|
|
13
|
+
*/
|
|
14
|
+
export const LOG_LEVEL_PRIORITY = {
|
|
15
|
+
[LogLevel.DEBUG]: 0,
|
|
16
|
+
[LogLevel.INFO]: 1,
|
|
17
|
+
[LogLevel.WARN]: 2,
|
|
18
|
+
[LogLevel.ERROR]: 3,
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA6B;IAC1D,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Logger } from './core/Logger.js';
|
|
2
|
+
export { CorrelationContextManager } from './core/CorrelationContextManager.js';
|
|
3
|
+
export { LogLevel, LOG_LEVEL_PRIORITY, type LogEntry, type LogContext, type LoggerConfig, } from './core/types.js';
|
|
4
|
+
export { type LogTransport } from './transports/LogTransport.js';
|
|
5
|
+
export { ConsoleTransport } from './transports/ConsoleTransport.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Core
|
|
2
|
+
export { Logger } from './core/Logger.js';
|
|
3
|
+
export { CorrelationContextManager } from './core/CorrelationContextManager.js';
|
|
4
|
+
export { LogLevel, LOG_LEVEL_PRIORITY, } from './core/types.js';
|
|
5
|
+
export { ConsoleTransport } from './transports/ConsoleTransport.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EACL,QAAQ,EACR,kBAAkB,GAInB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type LogEntry } from '../core/types.js';
|
|
2
|
+
import type { LogTransport } from './LogTransport.js';
|
|
3
|
+
/**
|
|
4
|
+
* Console log transport
|
|
5
|
+
*
|
|
6
|
+
* Outputs logs to stdout (info/debug) or stderr (warn/error)
|
|
7
|
+
* with optional colorization and formatting
|
|
8
|
+
*/
|
|
9
|
+
export declare class ConsoleTransport implements LogTransport {
|
|
10
|
+
private json;
|
|
11
|
+
private colorize;
|
|
12
|
+
private static readonly COLORS;
|
|
13
|
+
constructor(options?: {
|
|
14
|
+
json?: boolean;
|
|
15
|
+
colorize?: boolean;
|
|
16
|
+
});
|
|
17
|
+
log(entry: LogEntry): void;
|
|
18
|
+
/**
|
|
19
|
+
* Output JSON log entry
|
|
20
|
+
*/
|
|
21
|
+
private logJson;
|
|
22
|
+
/**
|
|
23
|
+
* Output formatted (human-readable) log entry
|
|
24
|
+
*/
|
|
25
|
+
private logFormatted;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ConsoleTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConsoleTransport.d.ts","sourceRoot":"","sources":["../../src/transports/ConsoleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,QAAQ,CAAU;IAG1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAM5B;gBAEU,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO;IAKhE,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAQ1B;;OAEG;IACH,OAAO,CAAC,OAAO;IAWf;;OAEG;IACH,OAAO,CAAC,YAAY;CAyCrB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LogLevel } from '../core/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Console log transport
|
|
4
|
+
*
|
|
5
|
+
* Outputs logs to stdout (info/debug) or stderr (warn/error)
|
|
6
|
+
* with optional colorization and formatting
|
|
7
|
+
*/
|
|
8
|
+
export class ConsoleTransport {
|
|
9
|
+
json;
|
|
10
|
+
colorize;
|
|
11
|
+
// ANSI color codes
|
|
12
|
+
static COLORS = {
|
|
13
|
+
debug: '\x1b[36m', // Cyan
|
|
14
|
+
info: '\x1b[32m', // Green
|
|
15
|
+
warn: '\x1b[33m', // Yellow
|
|
16
|
+
error: '\x1b[31m', // Red
|
|
17
|
+
reset: '\x1b[0m',
|
|
18
|
+
};
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.json = options.json ?? true;
|
|
21
|
+
this.colorize = options.colorize ?? false;
|
|
22
|
+
}
|
|
23
|
+
log(entry) {
|
|
24
|
+
if (this.json) {
|
|
25
|
+
this.logJson(entry);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.logFormatted(entry);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Output JSON log entry
|
|
33
|
+
*/
|
|
34
|
+
logJson(entry) {
|
|
35
|
+
const output = JSON.stringify(entry);
|
|
36
|
+
// Use stderr for errors and warnings
|
|
37
|
+
if (entry.level === LogLevel.ERROR || entry.level === LogLevel.WARN) {
|
|
38
|
+
console.error(output);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.log(output);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Output formatted (human-readable) log entry
|
|
46
|
+
*/
|
|
47
|
+
logFormatted(entry) {
|
|
48
|
+
const color = this.colorize ? ConsoleTransport.COLORS[entry.level] : '';
|
|
49
|
+
const reset = this.colorize ? ConsoleTransport.COLORS.reset : '';
|
|
50
|
+
// Build log line
|
|
51
|
+
const parts = [
|
|
52
|
+
entry.timestamp,
|
|
53
|
+
`${color}[${entry.level.toUpperCase()}]${reset}`,
|
|
54
|
+
entry.service,
|
|
55
|
+
entry.correlationId && `(${entry.correlationId})`,
|
|
56
|
+
entry.message,
|
|
57
|
+
].filter(Boolean);
|
|
58
|
+
const logLine = parts.join(' ');
|
|
59
|
+
// Output main log line
|
|
60
|
+
if (entry.level === LogLevel.ERROR || entry.level === LogLevel.WARN) {
|
|
61
|
+
console.error(logLine);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.log(logLine);
|
|
65
|
+
}
|
|
66
|
+
// Output metadata if present
|
|
67
|
+
if (entry.metadata && Object.keys(entry.metadata).length > 0) {
|
|
68
|
+
console.log(' Metadata:', JSON.stringify(entry.metadata, null, 2));
|
|
69
|
+
}
|
|
70
|
+
// Output error details if present
|
|
71
|
+
if (entry.error) {
|
|
72
|
+
console.error(' Error:', entry.error.name, '-', entry.error.message);
|
|
73
|
+
if (entry.error.code) {
|
|
74
|
+
console.error(' Code:', entry.error.code);
|
|
75
|
+
}
|
|
76
|
+
if (entry.error.stack) {
|
|
77
|
+
console.error(' Stack:', entry.error.stack);
|
|
78
|
+
}
|
|
79
|
+
if (entry.error.metadata) {
|
|
80
|
+
console.error(' Error Metadata:', JSON.stringify(entry.error.metadata, null, 2));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=ConsoleTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConsoleTransport.js","sourceRoot":"","sources":["../../src/transports/ConsoleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAiB,MAAM,kBAAkB,CAAC;AAG3D;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACnB,IAAI,CAAU;IACd,QAAQ,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SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7C,CAAC;YACD,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC/C,CAAC;YACD,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LogEntry } from '../core/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for log transports
|
|
4
|
+
*
|
|
5
|
+
* A transport is responsible for outputting log entries
|
|
6
|
+
* to a specific destination (console, file, external service, etc.)
|
|
7
|
+
*/
|
|
8
|
+
export interface LogTransport {
|
|
9
|
+
/**
|
|
10
|
+
* Output a log entry
|
|
11
|
+
*
|
|
12
|
+
* @param entry - The log entry to output
|
|
13
|
+
*/
|
|
14
|
+
log(entry: LogEntry): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=LogTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogTransport.d.ts","sourceRoot":"","sources":["../../src/transports/LogTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogTransport.js","sourceRoot":"","sources":["../../src/transports/LogTransport.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@beethovn/logging",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Structured logging with correlation tracking for the Beethovn platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"logging",
|
|
16
|
+
"structured-logging",
|
|
17
|
+
"correlation",
|
|
18
|
+
"typescript",
|
|
19
|
+
"beethovn"
|
|
20
|
+
],
|
|
21
|
+
"author": "Beethovn Team",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@beethovn/errors": "1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"typescript": "^5.3.3",
|
|
29
|
+
"vitest": "^1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"lint": "eslint src --ext .ts",
|
|
40
|
+
"type-check": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|