@hamak/logging-api 0.4.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.
Files changed (41) hide show
  1. package/dist/api/index.d.ts +4 -0
  2. package/dist/api/index.d.ts.map +1 -0
  3. package/dist/api/index.js +3 -0
  4. package/dist/api/logger.d.ts +105 -0
  5. package/dist/api/logger.d.ts.map +1 -0
  6. package/dist/api/logger.js +1 -0
  7. package/dist/api/manager.d.ts +120 -0
  8. package/dist/api/manager.d.ts.map +1 -0
  9. package/dist/api/manager.js +1 -0
  10. package/dist/api/transport.d.ts +97 -0
  11. package/dist/api/transport.d.ts.map +1 -0
  12. package/dist/api/transport.js +1 -0
  13. package/dist/es2015/api/index.js +3 -0
  14. package/dist/es2015/api/logger.js +1 -0
  15. package/dist/es2015/api/manager.js +1 -0
  16. package/dist/es2015/api/transport.js +1 -0
  17. package/dist/es2015/index.js +14 -0
  18. package/dist/es2015/tokens/index.js +1 -0
  19. package/dist/es2015/tokens/service-tokens.js +42 -0
  20. package/dist/es2015/types/index.js +2 -0
  21. package/dist/es2015/types/log-config.js +1 -0
  22. package/dist/es2015/types/log-entry.js +12 -0
  23. package/dist/index.d.ts +12 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +14 -0
  26. package/dist/tokens/index.d.ts +2 -0
  27. package/dist/tokens/index.d.ts.map +1 -0
  28. package/dist/tokens/index.js +1 -0
  29. package/dist/tokens/service-tokens.d.ts +51 -0
  30. package/dist/tokens/service-tokens.d.ts.map +1 -0
  31. package/dist/tokens/service-tokens.js +42 -0
  32. package/dist/types/index.d.ts +3 -0
  33. package/dist/types/index.d.ts.map +1 -0
  34. package/dist/types/index.js +2 -0
  35. package/dist/types/log-config.d.ts +72 -0
  36. package/dist/types/log-config.d.ts.map +1 -0
  37. package/dist/types/log-config.js +1 -0
  38. package/dist/types/log-entry.d.ts +64 -0
  39. package/dist/types/log-entry.d.ts.map +1 -0
  40. package/dist/types/log-entry.js +12 -0
  41. package/package.json +47 -0
@@ -0,0 +1,4 @@
1
+ export * from './logger.js';
2
+ export * from './transport.js';
3
+ export * from './manager.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './logger.js';
2
+ export * from './transport.js';
3
+ export * from './manager.js';
@@ -0,0 +1,105 @@
1
+ import { LogLevel, LogContext, LogMetadata } from '../types/index.js';
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/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEtE;;;;;;;;;;;;;;;;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.js';
2
+ import { ILogTransport } from './transport.js';
3
+ import { LogLevel, LogContext, TransportConfig, LogEntry } from '../types/index.js';
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/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEpF;;;;;;;;;;;;;;;;;;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.js';
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/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;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,3 @@
1
+ export * from './logger.js';
2
+ export * from './transport.js';
3
+ export * from './manager.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -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 './api/index.js';
11
+ // Export all types
12
+ export * from './types/index.js';
13
+ // Export service tokens
14
+ export * from './tokens/index.js';
@@ -0,0 +1 @@
1
+ export * from './service-tokens.js';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Dependency Injection tokens for logging services
3
+ */
4
+ /**
5
+ * Token for injecting the LogManager service
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * export const myPlugin: PluginModule = {
10
+ * initialize(ctx) {
11
+ * const logManager = ctx.resolve(LOG_MANAGER_TOKEN);
12
+ * const logger = logManager.createLogger({ plugin: 'my-plugin' });
13
+ * }
14
+ * };
15
+ * ```
16
+ */
17
+ export const LOG_MANAGER_TOKEN = Symbol.for('@hamak/logging:LogManager');
18
+ /**
19
+ * Token for injecting a Logger instance
20
+ * This is typically a factory that creates plugin-scoped loggers
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * export const myPlugin: PluginModule = {
25
+ * initialize(ctx) {
26
+ * // Get logger factory
27
+ * const createLogger = ctx.resolve(LOGGER_TOKEN);
28
+ * const logger = createLogger('my-plugin');
29
+ * }
30
+ * };
31
+ * ```
32
+ */
33
+ export const LOGGER_TOKEN = Symbol.for('@hamak/logging:Logger');
34
+ /**
35
+ * Token for injecting the LogConfig
36
+ */
37
+ export const LOG_CONFIG_TOKEN = Symbol.for('@hamak/logging:Config');
38
+ /**
39
+ * Token for injecting the transport registry
40
+ * Used internally by the logging system
41
+ */
42
+ export const LOG_TRANSPORTS_TOKEN = Symbol.for('@hamak/logging:Transports');
@@ -0,0 +1,2 @@
1
+ export * from './log-entry.js';
2
+ export * from './log-config.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Log severity levels
3
+ */
4
+ export var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel[LogLevel["TRACE"] = 0] = "TRACE";
7
+ LogLevel[LogLevel["DEBUG"] = 1] = "DEBUG";
8
+ LogLevel[LogLevel["INFO"] = 2] = "INFO";
9
+ LogLevel[LogLevel["WARN"] = 3] = "WARN";
10
+ LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
11
+ LogLevel[LogLevel["FATAL"] = 5] = "FATAL";
12
+ })(LogLevel || (LogLevel = {}));
@@ -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 './api/index.js';
10
+ export * from './types/index.js';
11
+ export * from './tokens/index.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -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 './api/index.js';
11
+ // Export all types
12
+ export * from './types/index.js';
13
+ // Export service tokens
14
+ export * from './tokens/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './service-tokens.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './service-tokens.js';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Dependency Injection tokens for logging services
3
+ */
4
+ /**
5
+ * Token for injecting the LogManager service
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * export const myPlugin: PluginModule = {
10
+ * initialize(ctx) {
11
+ * const logManager = ctx.resolve(LOG_MANAGER_TOKEN);
12
+ * const logger = logManager.createLogger({ plugin: 'my-plugin' });
13
+ * }
14
+ * };
15
+ * ```
16
+ */
17
+ export declare const LOG_MANAGER_TOKEN: unique symbol;
18
+ /**
19
+ * Token for injecting a Logger instance
20
+ * This is typically a factory that creates plugin-scoped loggers
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * export const myPlugin: PluginModule = {
25
+ * initialize(ctx) {
26
+ * // Get logger factory
27
+ * const createLogger = ctx.resolve(LOGGER_TOKEN);
28
+ * const logger = createLogger('my-plugin');
29
+ * }
30
+ * };
31
+ * ```
32
+ */
33
+ export declare const LOGGER_TOKEN: unique symbol;
34
+ /**
35
+ * Token for injecting the LogConfig
36
+ */
37
+ export declare const LOG_CONFIG_TOKEN: unique symbol;
38
+ /**
39
+ * Token for injecting the transport registry
40
+ * Used internally by the logging system
41
+ */
42
+ export declare const LOG_TRANSPORTS_TOKEN: unique symbol;
43
+ /**
44
+ * Type helper for LOG_MANAGER_TOKEN
45
+ */
46
+ export type LogManagerToken = typeof LOG_MANAGER_TOKEN;
47
+ /**
48
+ * Type helper for LOGGER_TOKEN
49
+ */
50
+ export type LoggerToken = typeof LOGGER_TOKEN;
51
+ //# sourceMappingURL=service-tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-tokens.d.ts","sourceRoot":"","sources":["../../src/tokens/service-tokens.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,eAA0C,CAAC;AAEzE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,eAAsC,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,gBAAgB,eAAsC,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAA0C,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,iBAAiB,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Dependency Injection tokens for logging services
3
+ */
4
+ /**
5
+ * Token for injecting the LogManager service
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * export const myPlugin: PluginModule = {
10
+ * initialize(ctx) {
11
+ * const logManager = ctx.resolve(LOG_MANAGER_TOKEN);
12
+ * const logger = logManager.createLogger({ plugin: 'my-plugin' });
13
+ * }
14
+ * };
15
+ * ```
16
+ */
17
+ export const LOG_MANAGER_TOKEN = Symbol.for('@hamak/logging:LogManager');
18
+ /**
19
+ * Token for injecting a Logger instance
20
+ * This is typically a factory that creates plugin-scoped loggers
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * export const myPlugin: PluginModule = {
25
+ * initialize(ctx) {
26
+ * // Get logger factory
27
+ * const createLogger = ctx.resolve(LOGGER_TOKEN);
28
+ * const logger = createLogger('my-plugin');
29
+ * }
30
+ * };
31
+ * ```
32
+ */
33
+ export const LOGGER_TOKEN = Symbol.for('@hamak/logging:Logger');
34
+ /**
35
+ * Token for injecting the LogConfig
36
+ */
37
+ export const LOG_CONFIG_TOKEN = Symbol.for('@hamak/logging:Config');
38
+ /**
39
+ * Token for injecting the transport registry
40
+ * Used internally by the logging system
41
+ */
42
+ export const LOG_TRANSPORTS_TOKEN = Symbol.for('@hamak/logging:Transports');
@@ -0,0 +1,3 @@
1
+ export * from './log-entry.js';
2
+ export * from './log-config.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './log-entry.js';
2
+ export * from './log-config.js';
@@ -0,0 +1,72 @@
1
+ import { LogLevel, LogEntry } from './log-entry.js';
2
+ /**
3
+ * Configuration for a log transport
4
+ */
5
+ export interface TransportConfig {
6
+ /** Unique identifier for the transport */
7
+ id: string;
8
+ /** Whether the transport is enabled */
9
+ enabled?: boolean;
10
+ /** Minimum log level to handle */
11
+ minLevel?: LogLevel;
12
+ /** Maximum log level to handle */
13
+ maxLevel?: LogLevel;
14
+ /** Custom filter function */
15
+ filter?: (entry: LogEntry) => boolean;
16
+ /** Only log from specific plugins */
17
+ plugins?: string[];
18
+ /** Only log from specific modules */
19
+ modules?: string[];
20
+ /** Only log entries with specific tags */
21
+ tags?: string[];
22
+ }
23
+ /**
24
+ * Configuration for the log manager
25
+ */
26
+ export interface LogManagerConfig {
27
+ /** Global minimum log level */
28
+ globalLevel?: LogLevel;
29
+ /** Buffer size before forcing flush */
30
+ bufferSize?: number;
31
+ /** Automatic flush interval in milliseconds */
32
+ flushInterval?: number;
33
+ /** Default transports to register */
34
+ defaultTransports?: TransportConfig[];
35
+ /** Plugin-specific log levels */
36
+ pluginLevels?: Record<string, LogLevel>;
37
+ /** Module-specific log levels */
38
+ moduleLevels?: Record<string, LogLevel>;
39
+ }
40
+ /**
41
+ * Configuration for console transport
42
+ */
43
+ export interface ConsoleTransportConfig {
44
+ /** Use colors in output */
45
+ colors?: boolean;
46
+ /** Use emojis in output */
47
+ emojis?: boolean;
48
+ /** Show timestamps */
49
+ timestamps?: boolean;
50
+ /** Show context (plugin/module/component) */
51
+ showContext?: boolean;
52
+ }
53
+ /**
54
+ * Configuration for remote transport
55
+ */
56
+ export interface RemoteTransportConfig {
57
+ /** Remote logging endpoint URL */
58
+ endpoint: string;
59
+ /** API key for authentication */
60
+ apiKey?: string;
61
+ /** Client identifier */
62
+ clientId?: string;
63
+ /** Environment (dev, staging, production) */
64
+ environment?: string;
65
+ /** Batch size for sending logs */
66
+ batchSize?: number;
67
+ /** Timeout for requests in milliseconds */
68
+ timeout?: number;
69
+ /** Retry attempts on failure */
70
+ retryAttempts?: number;
71
+ }
72
+ //# sourceMappingURL=log-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-config.d.ts","sourceRoot":"","sources":["../../src/types/log-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,uCAAuC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC;IACtC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+BAA+B;IAC/B,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC;IACtC,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxC,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,2BAA2B;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2BAA2B;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sBAAsB;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Log severity levels
3
+ */
4
+ export declare enum LogLevel {
5
+ TRACE = 0,
6
+ DEBUG = 1,
7
+ INFO = 2,
8
+ WARN = 3,
9
+ ERROR = 4,
10
+ FATAL = 5
11
+ }
12
+ /**
13
+ * Context information for a log entry
14
+ * Automatically tracks plugin, module, component hierarchy
15
+ */
16
+ export interface LogContext {
17
+ /** Plugin that created the log */
18
+ plugin?: string;
19
+ /** Module within the plugin */
20
+ module?: string;
21
+ /** Component (e.g., React component name) */
22
+ component?: string;
23
+ /** Operation being performed */
24
+ operation?: string;
25
+ /** Request ID for distributed tracing */
26
+ requestId?: string;
27
+ /** User ID for user-specific logs */
28
+ userId?: string;
29
+ /** Additional custom context */
30
+ [key: string]: any;
31
+ }
32
+ /**
33
+ * Additional metadata for a log entry
34
+ */
35
+ export interface LogMetadata {
36
+ /** Error object (for ERROR/FATAL logs) */
37
+ error?: Error;
38
+ /** Stack trace */
39
+ stack?: string;
40
+ /** Duration in milliseconds (for performance logs) */
41
+ duration?: number;
42
+ /** Tags for categorization */
43
+ tags?: string[];
44
+ /** Additional custom metadata */
45
+ [key: string]: any;
46
+ }
47
+ /**
48
+ * Complete log entry
49
+ */
50
+ export interface LogEntry {
51
+ /** Timestamp in milliseconds since epoch */
52
+ timestamp: number;
53
+ /** Log severity level */
54
+ level: LogLevel;
55
+ /** Log message */
56
+ message: string;
57
+ /** Context information */
58
+ context: LogContext;
59
+ /** Additional metadata */
60
+ metadata?: LogMetadata;
61
+ /** Pre-formatted message (optional, for caching) */
62
+ formattedMessage?: string;
63
+ }
64
+ //# sourceMappingURL=log-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-entry.d.ts","sourceRoot":"","sources":["../../src/types/log-entry.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,KAAK,IAAI;CACV;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,0CAA0C;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,iCAAiC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,KAAK,EAAE,QAAQ,CAAC;IAChB,kBAAkB;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,OAAO,EAAE,UAAU,CAAC;IACpB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Log severity levels
3
+ */
4
+ export var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel[LogLevel["TRACE"] = 0] = "TRACE";
7
+ LogLevel[LogLevel["DEBUG"] = 1] = "DEBUG";
8
+ LogLevel[LogLevel["INFO"] = 2] = "INFO";
9
+ LogLevel[LogLevel["WARN"] = 3] = "WARN";
10
+ LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
11
+ LogLevel[LogLevel["FATAL"] = 5] = "FATAL";
12
+ })(LogLevel || (LogLevel = {}));
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@hamak/logging-api",
3
+ "version": "0.4.0",
4
+ "description": "Logging API - Public interfaces and types for pluggable logging system",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js",
13
+ "legacy": "./dist/es2015/index.js"
14
+ },
15
+ "./es2015": {
16
+ "import": "./dist/es2015/index.js",
17
+ "default": "./dist/es2015/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/amah/app-framework.git",
26
+ "directory": "packages/logging/logging-api"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.lib.json && tsc -p tsconfig.es2015.json",
33
+ "clean": "rm -rf dist"
34
+ },
35
+ "keywords": [
36
+ "logging",
37
+ "api",
38
+ "interfaces",
39
+ "microkernel"
40
+ ],
41
+ "author": "",
42
+ "license": "MIT",
43
+ "devDependencies": {
44
+ "typescript": "^5.9.3",
45
+ "vitest": "^3.2.4"
46
+ }
47
+ }