@hamak/logging 0.5.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/README.md +252 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +14 -0
- package/dist/api/interfaces/index.d.ts +4 -0
- package/dist/api/interfaces/index.d.ts.map +1 -0
- package/dist/api/interfaces/index.js +3 -0
- package/dist/api/interfaces/logger.d.ts +105 -0
- package/dist/api/interfaces/logger.d.ts.map +1 -0
- package/dist/api/interfaces/logger.js +1 -0
- package/dist/api/interfaces/manager.d.ts +120 -0
- package/dist/api/interfaces/manager.d.ts.map +1 -0
- package/dist/api/interfaces/manager.js +1 -0
- package/dist/api/interfaces/transport.d.ts +97 -0
- package/dist/api/interfaces/transport.d.ts.map +1 -0
- package/dist/api/interfaces/transport.js +1 -0
- package/dist/api/tokens/index.d.ts +2 -0
- package/dist/api/tokens/index.d.ts.map +1 -0
- package/dist/api/tokens/index.js +1 -0
- package/dist/api/tokens/service-tokens.d.ts +51 -0
- package/dist/api/tokens/service-tokens.d.ts.map +1 -0
- package/dist/api/tokens/service-tokens.js +42 -0
- package/dist/api/types/index.d.ts +3 -0
- package/dist/api/types/index.d.ts.map +1 -0
- package/dist/api/types/index.js +2 -0
- package/dist/api/types/log-config.d.ts +72 -0
- package/dist/api/types/log-config.d.ts.map +1 -0
- package/dist/api/types/log-config.js +1 -0
- package/dist/api/types/log-entry.d.ts +64 -0
- package/dist/api/types/log-entry.d.ts.map +1 -0
- package/dist/api/types/log-entry.js +12 -0
- package/dist/impl/core/context-logger.d.ts +26 -0
- package/dist/impl/core/context-logger.d.ts.map +1 -0
- package/dist/impl/core/context-logger.js +102 -0
- package/dist/impl/core/index.d.ts +3 -0
- package/dist/impl/core/index.d.ts.map +1 -0
- package/dist/impl/core/index.js +2 -0
- package/dist/impl/core/log-manager.d.ts +41 -0
- package/dist/impl/core/log-manager.d.ts.map +1 -0
- package/dist/impl/core/log-manager.js +278 -0
- package/dist/impl/formatters/dev-formatter.d.ts +20 -0
- package/dist/impl/formatters/dev-formatter.d.ts.map +1 -0
- package/dist/impl/formatters/dev-formatter.js +145 -0
- package/dist/impl/formatters/index.d.ts +3 -0
- package/dist/impl/formatters/index.d.ts.map +1 -0
- package/dist/impl/formatters/index.js +2 -0
- package/dist/impl/formatters/json-formatter.d.ts +24 -0
- package/dist/impl/formatters/json-formatter.d.ts.map +1 -0
- package/dist/impl/formatters/json-formatter.js +70 -0
- package/dist/impl/index.d.ts +16 -0
- package/dist/impl/index.d.ts.map +1 -0
- package/dist/impl/index.js +19 -0
- package/dist/impl/plugin/index.d.ts +2 -0
- package/dist/impl/plugin/index.d.ts.map +1 -0
- package/dist/impl/plugin/index.js +1 -0
- package/dist/impl/plugin/logging-plugin-factory.d.ts +37 -0
- package/dist/impl/plugin/logging-plugin-factory.d.ts.map +1 -0
- package/dist/impl/plugin/logging-plugin-factory.js +112 -0
- package/dist/impl/transports/console-transport.d.ts +16 -0
- package/dist/impl/transports/console-transport.d.ts.map +1 -0
- package/dist/impl/transports/console-transport.js +55 -0
- package/dist/impl/transports/index.d.ts +2 -0
- package/dist/impl/transports/index.d.ts.map +1 -0
- package/dist/impl/transports/index.js +1 -0
- package/dist/impl/utils/console-interceptor.d.ts +36 -0
- package/dist/impl/utils/console-interceptor.d.ts.map +1 -0
- package/dist/impl/utils/console-interceptor.js +121 -0
- package/dist/impl/utils/event-emitter.d.ts +11 -0
- package/dist/impl/utils/event-emitter.d.ts.map +1 -0
- package/dist/impl/utils/event-emitter.js +44 -0
- package/dist/impl/utils/index.d.ts +3 -0
- package/dist/impl/utils/index.d.ts.map +1 -0
- package/dist/impl/utils/index.js +2 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/spi/formatter/formatter-provider.d.ts +67 -0
- package/dist/spi/formatter/formatter-provider.d.ts.map +1 -0
- package/dist/spi/formatter/formatter-provider.js +1 -0
- package/dist/spi/formatter/index.d.ts +2 -0
- package/dist/spi/formatter/index.d.ts.map +1 -0
- package/dist/spi/formatter/index.js +1 -0
- package/dist/spi/index.d.ts +12 -0
- package/dist/spi/index.d.ts.map +1 -0
- package/dist/spi/index.js +12 -0
- package/dist/spi/transport/index.d.ts +2 -0
- package/dist/spi/transport/index.d.ts.map +1 -0
- package/dist/spi/transport/index.js +1 -0
- package/dist/spi/transport/transport-provider.d.ts +89 -0
- package/dist/spi/transport/transport-provider.d.ts.map +1 -0
- package/dist/spi/transport/transport-provider.js +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# Pluggable Logging System
|
|
2
|
+
|
|
3
|
+
A comprehensive, pluggable logging system for the app-framework monorepo.
|
|
4
|
+
|
|
5
|
+
## Packages
|
|
6
|
+
|
|
7
|
+
- **`@hamak/logging-api`** - Public interfaces and types
|
|
8
|
+
- **`@hamak/logging-spi`** - Service Provider Interfaces for extensions
|
|
9
|
+
- **`@hamak/logging-impl`** - Core implementation
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createLoggingPlugin } from '@hamak/logging-impl';
|
|
15
|
+
import { LogLevel } from '@hamak/logging-api';
|
|
16
|
+
|
|
17
|
+
// Create logging plugin with default configuration
|
|
18
|
+
const loggingPlugin = createLoggingPlugin();
|
|
19
|
+
|
|
20
|
+
// Or with custom configuration
|
|
21
|
+
const loggingPlugin = createLoggingPlugin({
|
|
22
|
+
globalLevel: LogLevel.DEBUG,
|
|
23
|
+
interceptConsole: true, // Default: true
|
|
24
|
+
devFormatter: true, // Default: true in development
|
|
25
|
+
pluginLevels: {
|
|
26
|
+
'my-plugin': LogLevel.TRACE
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Use in microkernel
|
|
31
|
+
const host = createHost({
|
|
32
|
+
plugins: [loggingPlugin, myPlugin]
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
### ✅ Context-Aware Logging
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
export const myPlugin: PluginModule = {
|
|
42
|
+
initialize(ctx) {
|
|
43
|
+
const logManager = ctx.resolve(LOG_MANAGER_TOKEN);
|
|
44
|
+
const logger = logManager.createLogger({ plugin: 'my-plugin' });
|
|
45
|
+
|
|
46
|
+
logger.info('Plugin initializing');
|
|
47
|
+
// Output: ℹ️ INFO [my-plugin] Plugin initializing
|
|
48
|
+
|
|
49
|
+
const childLogger = logger.child({ module: 'auth' });
|
|
50
|
+
childLogger.warn('Authentication failed');
|
|
51
|
+
// Output: ⚠️ WARN [my-plugin] {auth} Authentication failed
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### ✅ Console Interception (Default: Enabled)
|
|
57
|
+
|
|
58
|
+
**All `console.log/warn/error` calls automatically route through the logging system!**
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// With interception enabled (default)
|
|
62
|
+
console.log('Hello world');
|
|
63
|
+
// → Routes through logger.info('Hello world')
|
|
64
|
+
|
|
65
|
+
console.warn('Warning message');
|
|
66
|
+
// → Routes through logger.warn('Warning message')
|
|
67
|
+
|
|
68
|
+
console.error('Error occurred', new Error('details'));
|
|
69
|
+
// → Routes through logger.error('Error occurred', error)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Disable if needed:**
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const loggingPlugin = createLoggingPlugin({
|
|
76
|
+
interceptConsole: false // Disable console interception
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### ✅ Performance Timing
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
logger.time('database-query');
|
|
84
|
+
await db.query('SELECT * FROM users');
|
|
85
|
+
logger.timeEnd('database-query');
|
|
86
|
+
// Output: 🐛 DEBUG {module} database-query ⏱ 45ms #performance
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### ✅ Structured Metadata
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
logger.info('User logged in', {
|
|
93
|
+
userId: '123',
|
|
94
|
+
timestamp: Date.now(),
|
|
95
|
+
tags: ['auth', 'user-event']
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### ✅ Multiple Log Levels
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
logger.trace('Very detailed debug info');
|
|
103
|
+
logger.debug('Debug information');
|
|
104
|
+
logger.info('General information');
|
|
105
|
+
logger.warn('Warning message');
|
|
106
|
+
logger.error('Error occurred', error);
|
|
107
|
+
logger.fatal('Fatal error', error);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### ✅ Rich Development Output
|
|
111
|
+
|
|
112
|
+
In development mode, logs include:
|
|
113
|
+
- 🎨 **Colors** - Different colors per log level
|
|
114
|
+
- 🎭 **Emojis** - Visual indicators for each level
|
|
115
|
+
- 📍 **Context** - Plugin/module/component hierarchy
|
|
116
|
+
- ⏱️ **Performance** - Duration tracking
|
|
117
|
+
- 🏷️ **Tags** - Categorization and filtering
|
|
118
|
+
|
|
119
|
+
### ✅ JSON Output for Production
|
|
120
|
+
|
|
121
|
+
In production mode, logs are structured JSON:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"timestamp": 1699564800000,
|
|
126
|
+
"level": "INFO",
|
|
127
|
+
"message": "User logged in",
|
|
128
|
+
"context": {
|
|
129
|
+
"plugin": "auth",
|
|
130
|
+
"module": "login"
|
|
131
|
+
},
|
|
132
|
+
"metadata": {
|
|
133
|
+
"userId": "123",
|
|
134
|
+
"tags": ["auth", "user-event"]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Configuration Options
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
interface LoggingPluginConfig {
|
|
143
|
+
/** Global minimum log level */
|
|
144
|
+
globalLevel?: LogLevel;
|
|
145
|
+
|
|
146
|
+
/** Plugin-specific log levels */
|
|
147
|
+
pluginLevels?: Record<string, LogLevel>;
|
|
148
|
+
|
|
149
|
+
/** Module-specific log levels */
|
|
150
|
+
moduleLevels?: Record<string, LogLevel>;
|
|
151
|
+
|
|
152
|
+
/** Buffer size before forcing flush */
|
|
153
|
+
bufferSize?: number; // Default: 1000
|
|
154
|
+
|
|
155
|
+
/** Automatic flush interval in milliseconds */
|
|
156
|
+
flushInterval?: number; // Default: 5000
|
|
157
|
+
|
|
158
|
+
/** Use rich development formatter */
|
|
159
|
+
devFormatter?: boolean; // Default: true in development
|
|
160
|
+
|
|
161
|
+
/** Intercept console.log/warn/error (ENABLED BY DEFAULT) */
|
|
162
|
+
interceptConsole?: boolean; // Default: true
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Advanced Usage
|
|
167
|
+
|
|
168
|
+
### Custom Transports
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { ILogTransport, LogEntry } from '@hamak/logging-api';
|
|
172
|
+
|
|
173
|
+
class MyCustomTransport implements ILogTransport {
|
|
174
|
+
readonly id = 'my-transport';
|
|
175
|
+
readonly name = 'My Custom Transport';
|
|
176
|
+
|
|
177
|
+
log(entry: LogEntry): void {
|
|
178
|
+
// Send to custom destination
|
|
179
|
+
fetch('/api/logs', {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
body: JSON.stringify(entry)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Register in plugin initialization
|
|
187
|
+
logManager.registerTransport(new MyCustomTransport(), {
|
|
188
|
+
id: 'my-transport',
|
|
189
|
+
enabled: true,
|
|
190
|
+
minLevel: LogLevel.WARN
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Filtering Logs
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
// Only log errors from 'payment' plugin
|
|
198
|
+
logManager.registerTransport(transport, {
|
|
199
|
+
id: 'payment-errors',
|
|
200
|
+
minLevel: LogLevel.ERROR,
|
|
201
|
+
plugins: ['payment']
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Only log entries with specific tags
|
|
205
|
+
logManager.registerTransport(transport, {
|
|
206
|
+
id: 'analytics',
|
|
207
|
+
filter: (entry) => entry.metadata?.tags?.includes('analytics')
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Accessing Log Manager
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
export const myPlugin: PluginModule = {
|
|
215
|
+
initialize(ctx) {
|
|
216
|
+
const logManager = ctx.resolve(LOG_MANAGER_TOKEN);
|
|
217
|
+
|
|
218
|
+
// Create logger
|
|
219
|
+
const logger = logManager.createLogger({ plugin: 'my-plugin' });
|
|
220
|
+
|
|
221
|
+
// Change log levels at runtime
|
|
222
|
+
logManager.setPluginLevel('my-plugin', LogLevel.TRACE);
|
|
223
|
+
logManager.setGlobalLevel(LogLevel.WARN);
|
|
224
|
+
|
|
225
|
+
// Flush logs manually
|
|
226
|
+
await logManager.flush();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Architecture
|
|
232
|
+
|
|
233
|
+
- **SPI/API/IMPL Pattern** - Clean separation of concerns
|
|
234
|
+
- **Dependency Injection** - Loggers injected via microkernel DI
|
|
235
|
+
- **Pluggable Transports** - Multiple output destinations
|
|
236
|
+
- **Event-Based** - Integrates with microkernel event system
|
|
237
|
+
- **Performance Optimized** - Buffering, batching, lazy formatting
|
|
238
|
+
- **Type-Safe** - Full TypeScript support
|
|
239
|
+
|
|
240
|
+
## Examples
|
|
241
|
+
|
|
242
|
+
See `apps/demo/src/` for complete integration examples.
|
|
243
|
+
|
|
244
|
+
## Documentation
|
|
245
|
+
|
|
246
|
+
- [Planning Document](../../plans/005-pluggable-logging-system.md)
|
|
247
|
+
- [Implementation Details](./logging-impl/src/)
|
|
248
|
+
- [API Reference](./logging-api/src/api/)
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hamak/logging/api
|
|
3
|
+
*
|
|
4
|
+
* Public API for the pluggable logging system.
|
|
5
|
+
* Provides interfaces, types, and service tokens for logging.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export * from './interfaces/index';
|
|
10
|
+
export * from './types/index';
|
|
11
|
+
export * from './tokens/index';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,oBAAoB,CAAC;AAGnC,cAAc,eAAe,CAAC;AAG9B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hamak/logging/api
|
|
3
|
+
*
|
|
4
|
+
* Public API for the pluggable logging system.
|
|
5
|
+
* Provides interfaces, types, and service tokens for logging.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// Export all API interfaces
|
|
10
|
+
export * from './interfaces/index';
|
|
11
|
+
// Export all types
|
|
12
|
+
export * from './types/index';
|
|
13
|
+
// Export service tokens
|
|
14
|
+
export * from './tokens/index';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { LogLevel, LogContext, LogMetadata } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* Core logging interface
|
|
4
|
+
*
|
|
5
|
+
* All logging in the application should go through this interface.
|
|
6
|
+
* Context is automatically tracked and can be extended with child loggers.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const logger = logManager.createLogger({ plugin: 'my-plugin' });
|
|
11
|
+
* logger.info('Application started');
|
|
12
|
+
* logger.debug('Config loaded', { config: myConfig });
|
|
13
|
+
*
|
|
14
|
+
* // Create child logger with additional context
|
|
15
|
+
* const moduleLogger = logger.child({ module: 'auth' });
|
|
16
|
+
* moduleLogger.warn('Failed login attempt', { userId: '123' });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface ILogger {
|
|
20
|
+
/**
|
|
21
|
+
* Log a trace message (most verbose)
|
|
22
|
+
* Use for very detailed debugging information
|
|
23
|
+
*/
|
|
24
|
+
trace(message: string, meta?: LogMetadata): void;
|
|
25
|
+
/**
|
|
26
|
+
* Log a debug message
|
|
27
|
+
* Use for debugging information useful during development
|
|
28
|
+
*/
|
|
29
|
+
debug(message: string, meta?: LogMetadata): void;
|
|
30
|
+
/**
|
|
31
|
+
* Log an informational message
|
|
32
|
+
* Use for general application flow information
|
|
33
|
+
*/
|
|
34
|
+
info(message: string, meta?: LogMetadata): void;
|
|
35
|
+
/**
|
|
36
|
+
* Log a warning message
|
|
37
|
+
* Use for potentially harmful situations
|
|
38
|
+
*/
|
|
39
|
+
warn(message: string, meta?: LogMetadata): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log an error message
|
|
42
|
+
* Use for error events that might still allow the app to continue
|
|
43
|
+
*/
|
|
44
|
+
error(message: string, error?: Error, meta?: LogMetadata): void;
|
|
45
|
+
/**
|
|
46
|
+
* Log a fatal error message
|
|
47
|
+
* Use for severe errors that will likely lead to application abort
|
|
48
|
+
*/
|
|
49
|
+
fatal(message: string, error?: Error, meta?: LogMetadata): void;
|
|
50
|
+
/**
|
|
51
|
+
* Create a child logger with additional context
|
|
52
|
+
* The child inherits all context from the parent and adds new context
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const pluginLogger = logger.child({ plugin: 'auth' });
|
|
57
|
+
* const moduleLogger = pluginLogger.child({ module: 'login' });
|
|
58
|
+
* // moduleLogger has context: { plugin: 'auth', module: 'login' }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
child(context: LogContext): ILogger;
|
|
62
|
+
/**
|
|
63
|
+
* Execute a function with temporary additional context
|
|
64
|
+
* Useful for scoped operations
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* logger.scoped({ requestId: '123' }, (scopedLogger) => {
|
|
69
|
+
* scopedLogger.info('Processing request');
|
|
70
|
+
* // logs will include requestId: '123'
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
scoped(context: LogContext, fn: (logger: ILogger) => void): void;
|
|
75
|
+
/**
|
|
76
|
+
* Check if a log level is enabled
|
|
77
|
+
* Useful for expensive operations that should only run if logging is enabled
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* if (logger.isLevelEnabled(LogLevel.DEBUG)) {
|
|
82
|
+
* logger.debug('Expensive data', expensiveSerialize(data));
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Start a performance timer
|
|
89
|
+
* Call timeEnd() with the same label to log the duration
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* logger.time('database-query');
|
|
94
|
+
* await db.query('SELECT * FROM users');
|
|
95
|
+
* logger.timeEnd('database-query'); // logs duration
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
time(label: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* End a performance timer and log the duration
|
|
101
|
+
* Must be called after time() with the same label
|
|
102
|
+
*/
|
|
103
|
+
timeEnd(label: string): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/api/interfaces/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEjD;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEjD;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEhD;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEhD;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEhE;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEhE;;;;;;;;;;OAUG;IACH,KAAK,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;IAEpC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IAEjE;;;;;;;;;;OAUG;IACH,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC;IAEzC;;;;;;;;;;OAUG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ILogger } from './logger';
|
|
2
|
+
import { ILogTransport } from './transport';
|
|
3
|
+
import { LogLevel, LogContext, TransportConfig, LogEntry } from '../types/index';
|
|
4
|
+
/**
|
|
5
|
+
* Log manager interface
|
|
6
|
+
*
|
|
7
|
+
* The central coordinator for the logging system.
|
|
8
|
+
* Manages transports, creates loggers, and dispatches log entries.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const logManager = new LogManager({ globalLevel: LogLevel.DEBUG });
|
|
13
|
+
*
|
|
14
|
+
* // Register transports
|
|
15
|
+
* logManager.registerTransport(new ConsoleTransport());
|
|
16
|
+
* logManager.registerTransport(new RemoteTransport(config));
|
|
17
|
+
*
|
|
18
|
+
* // Create loggers
|
|
19
|
+
* const logger = logManager.createLogger({ plugin: 'my-plugin' });
|
|
20
|
+
* logger.info('Application started');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface ILogManager {
|
|
24
|
+
/**
|
|
25
|
+
* Register a transport
|
|
26
|
+
* @param transport The transport to register
|
|
27
|
+
* @param config Optional configuration for this transport
|
|
28
|
+
*/
|
|
29
|
+
registerTransport(transport: ILogTransport, config?: TransportConfig): void;
|
|
30
|
+
/**
|
|
31
|
+
* Unregister a transport by ID
|
|
32
|
+
* @param id Transport identifier
|
|
33
|
+
*/
|
|
34
|
+
unregisterTransport(id: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get a transport by ID
|
|
37
|
+
* @param id Transport identifier
|
|
38
|
+
* @returns The transport or undefined if not found
|
|
39
|
+
*/
|
|
40
|
+
getTransport(id: string): ILogTransport | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Get all registered transports
|
|
43
|
+
* @returns Array of all transports
|
|
44
|
+
*/
|
|
45
|
+
listTransports(): ILogTransport[];
|
|
46
|
+
/**
|
|
47
|
+
* Create a new logger with the given context
|
|
48
|
+
* Creates a new logger instance each time
|
|
49
|
+
*
|
|
50
|
+
* @param context Initial context for the logger
|
|
51
|
+
* @returns A new logger instance
|
|
52
|
+
*/
|
|
53
|
+
createLogger(context?: LogContext): ILogger;
|
|
54
|
+
/**
|
|
55
|
+
* Get or create a cached logger for the given context
|
|
56
|
+
* Returns the same logger instance for the same context
|
|
57
|
+
*
|
|
58
|
+
* @param context Context for the logger
|
|
59
|
+
* @returns A cached logger instance
|
|
60
|
+
*/
|
|
61
|
+
getLogger(context?: LogContext): ILogger;
|
|
62
|
+
/**
|
|
63
|
+
* Set the global minimum log level
|
|
64
|
+
* Logs below this level will be ignored (unless overridden by plugin/module)
|
|
65
|
+
*
|
|
66
|
+
* @param level The minimum log level
|
|
67
|
+
*/
|
|
68
|
+
setGlobalLevel(level: LogLevel): void;
|
|
69
|
+
/**
|
|
70
|
+
* Set the minimum log level for a specific plugin
|
|
71
|
+
*
|
|
72
|
+
* @param plugin Plugin name
|
|
73
|
+
* @param level Minimum log level for this plugin
|
|
74
|
+
*/
|
|
75
|
+
setPluginLevel(plugin: string, level: LogLevel): void;
|
|
76
|
+
/**
|
|
77
|
+
* Set the minimum log level for a specific module
|
|
78
|
+
*
|
|
79
|
+
* @param module Module name
|
|
80
|
+
* @param level Minimum log level for this module
|
|
81
|
+
*/
|
|
82
|
+
setModuleLevel(module: string, level: LogLevel): void;
|
|
83
|
+
/**
|
|
84
|
+
* Flush all buffered logs to all transports
|
|
85
|
+
* @returns Promise that resolves when all logs are flushed
|
|
86
|
+
*/
|
|
87
|
+
flush(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Clear the internal log buffer
|
|
90
|
+
* Useful for testing or memory management
|
|
91
|
+
*/
|
|
92
|
+
clearBuffer(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Register an event listener
|
|
95
|
+
* Events: 'log', 'error', 'flush'
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* logManager.on('log', (entry: LogEntry) => {
|
|
100
|
+
* console.log('Log captured:', entry);
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
on(event: 'log' | 'error' | 'flush', handler: (...args: any[]) => void): void;
|
|
105
|
+
/**
|
|
106
|
+
* Remove an event listener
|
|
107
|
+
*
|
|
108
|
+
* @param event Event name
|
|
109
|
+
* @param handler Handler function to remove
|
|
110
|
+
*/
|
|
111
|
+
off(event: string, handler: (...args: any[]) => void): void;
|
|
112
|
+
/**
|
|
113
|
+
* Dispatch a log entry to all transports
|
|
114
|
+
* Internal method used by loggers
|
|
115
|
+
*
|
|
116
|
+
* @param entry The log entry to dispatch
|
|
117
|
+
*/
|
|
118
|
+
dispatch(entry: LogEntry): void;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/api/interfaces/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,iBAAiB,CAAC,SAAS,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAE5E;;;OAGG;IACH,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;;OAIG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAEpD;;;OAGG;IACH,cAAc,IAAI,aAAa,EAAE,CAAC;IAElC;;;;;;OAMG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAE5C;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAEzC;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEtC;;;;;OAKG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEtD;;;;;OAKG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEtD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,WAAW,IAAI,IAAI,CAAC;IAEpB;;;;;;;;;;OAUG;IACH,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAE9E;;;;;OAKG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAE5D;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { LogEntry } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* Log transport interface
|
|
4
|
+
*
|
|
5
|
+
* Transports are responsible for outputting logs to different destinations
|
|
6
|
+
* (console, file, remote API, event bus, etc.)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* class MyCustomTransport implements ILogTransport {
|
|
11
|
+
* readonly id = 'my-transport';
|
|
12
|
+
* readonly name = 'My Custom Transport';
|
|
13
|
+
*
|
|
14
|
+
* log(entry: LogEntry): void {
|
|
15
|
+
* // Send log to custom destination
|
|
16
|
+
* myService.sendLog(entry);
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* async flush(): Promise<void> {
|
|
20
|
+
* await myService.flushBuffer();
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface ILogTransport {
|
|
26
|
+
/** Unique identifier for the transport */
|
|
27
|
+
readonly id: string;
|
|
28
|
+
/** Human-readable name */
|
|
29
|
+
readonly name: string;
|
|
30
|
+
/**
|
|
31
|
+
* Handle a log entry
|
|
32
|
+
* Can be synchronous or asynchronous
|
|
33
|
+
*/
|
|
34
|
+
log(entry: LogEntry): void | Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Flush any buffered logs
|
|
37
|
+
* Optional - implement if transport buffers logs
|
|
38
|
+
*/
|
|
39
|
+
flush?(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Close the transport and release resources
|
|
42
|
+
* Optional - implement if transport needs cleanup
|
|
43
|
+
*/
|
|
44
|
+
close?(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Determine if this transport should handle a log entry
|
|
47
|
+
* Optional - implement for custom filtering beyond TransportConfig
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* shouldLog(entry: LogEntry): boolean {
|
|
52
|
+
* // Only log errors from production
|
|
53
|
+
* return entry.level >= LogLevel.ERROR &&
|
|
54
|
+
* entry.context.environment === 'production';
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
shouldLog?(entry: LogEntry): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Handle transport errors
|
|
61
|
+
* Optional - implement for custom error handling
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* onError(error: Error): void {
|
|
66
|
+
* console.error('[Transport Error]', error);
|
|
67
|
+
* // Maybe send to error tracking service
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
onError?(error: Error): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Log formatter interface
|
|
75
|
+
*
|
|
76
|
+
* Formatters convert LogEntry objects into formatted strings
|
|
77
|
+
* for display or transmission.
|
|
78
|
+
*/
|
|
79
|
+
export interface ILogFormatter {
|
|
80
|
+
/**
|
|
81
|
+
* Format a log entry into a string
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* format(entry: LogEntry): string {
|
|
86
|
+
* return `[${entry.level}] ${entry.message}`;
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
format(entry: LogEntry): string | any;
|
|
91
|
+
/**
|
|
92
|
+
* Format batch of log entries
|
|
93
|
+
* Optional - implement for efficient batch formatting
|
|
94
|
+
*/
|
|
95
|
+
formatBatch?(entries: LogEntry[]): string | any;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/api/interfaces/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3C;;;OAGG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;;OAGG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC;IAErC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,GAAG,CAAC;IAEtC;;;OAGG;IACH,WAAW,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,GAAG,GAAG,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/tokens/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './service-tokens';
|