@hamak/logging 0.14.2 → 0.16.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.
@@ -1,6 +1,23 @@
1
1
  import { ILogger } from './logger.js';
2
2
  import { ILogTransport } from './transport.js';
3
3
  import { LogLevel, LogContext, TransportConfig, LogEntry } from '../types/index.js';
4
+ /**
5
+ * Options for {@link ILogManager.createLogger}
6
+ */
7
+ export interface CreateLoggerOptions {
8
+ /**
9
+ * Have every record this logger creates bypass the buffer and dispatch to
10
+ * transports immediately (see {@link LogEntry.immediate}).
11
+ *
12
+ * Internal: set by the console interceptor (#87) for the logger it routes
13
+ * `console.*` calls through. Application code should not normally need
14
+ * this — it changes when a record reaches transports, not what gets
15
+ * logged.
16
+ *
17
+ * @default false
18
+ */
19
+ immediate?: boolean;
20
+ }
4
21
  /**
5
22
  * Log manager interface
6
23
  *
@@ -48,9 +65,10 @@ export interface ILogManager {
48
65
  * Creates a new logger instance each time
49
66
  *
50
67
  * @param context Initial context for the logger
68
+ * @param options Additional, non-context behavior for this logger
51
69
  * @returns A new logger instance
52
70
  */
53
- createLogger(context?: LogContext): ILogger;
71
+ createLogger(context?: LogContext, options?: CreateLoggerOptions): ILogger;
54
72
  /**
55
73
  * Get or create a cached logger for the given context
56
74
  * Returns the same logger instance for the same context
@@ -1 +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,C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;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"}
@@ -60,5 +60,16 @@ export interface LogEntry {
60
60
  metadata?: LogMetadata;
61
61
  /** Pre-formatted message (optional, for caching) */
62
62
  formattedMessage?: string;
63
+ /**
64
+ * Bypass the manager's buffer and dispatch to transports immediately,
65
+ * instead of waiting for the next flush.
66
+ *
67
+ * Set on records that come from the console interceptor (#87): an
68
+ * application's `console.log` is expected to appear synchronously, not up
69
+ * to `flushInterval` late or lost on an early process exit. Records logged
70
+ * through the logger API directly never set this and keep the existing
71
+ * buffered behavior.
72
+ */
73
+ immediate?: boolean;
63
74
  }
64
75
  //# sourceMappingURL=log-entry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"log-entry.d.ts","sourceRoot":"","sources":["../../../src/api/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;IACz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S,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;IAC1B;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -8,8 +8,22 @@ export declare class ContextLogger implements ILogger {
8
8
  private manager;
9
9
  private context;
10
10
  private minLevel;
11
+ /**
12
+ * Tag every entry this logger builds as {@link LogEntry.immediate}
13
+ * (#87). Set only for the logger the console interceptor routes
14
+ * `console.*` calls through; direct application logging leaves this
15
+ * `false` and keeps the existing buffered behavior.
16
+ */
17
+ private immediate;
11
18
  private timers;
12
- constructor(manager: ILogManager, context: LogContext | undefined, minLevel: LogLevel);
19
+ constructor(manager: ILogManager, context: LogContext | undefined, minLevel: LogLevel,
20
+ /**
21
+ * Tag every entry this logger builds as {@link LogEntry.immediate}
22
+ * (#87). Set only for the logger the console interceptor routes
23
+ * `console.*` calls through; direct application logging leaves this
24
+ * `false` and keeps the existing buffered behavior.
25
+ */
26
+ immediate?: boolean);
13
27
  trace(message: string, meta?: LogMetadata): void;
14
28
  debug(message: string, meta?: LogMetadata): void;
15
29
  info(message: string, meta?: LogMetadata): void;
@@ -1 +1 @@
1
- {"version":3,"file":"context-logger.d.ts","sourceRoot":"","sources":["../../../src/impl/core/context-logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/F;;;;GAIG;AACH,qBAAa,aAAc,YAAW,OAAO;IAIzC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;IALlB,OAAO,CAAC,MAAM,CAA6B;gBAGjC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,UAAU,YAAK,EACxB,QAAQ,EAAE,QAAQ;IAG5B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAKhD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAKhD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAK/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAK/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAS/D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAS/D,OA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EAAE,WAAW,GAAG,IAAI;IAS/D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI;IAS/D,OAAO,CAAC,GAAG;IAgBX,KAAK,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO;IASnC,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAKhE,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAIxC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAQ7B"}
@@ -4,7 +4,14 @@
4
4
  * Tracks plugin/module/component hierarchy and supports child loggers.
5
5
  */
6
6
  export class ContextLogger {
7
- constructor(manager, context = {}, minLevel) {
7
+ constructor(manager, context = {}, minLevel,
8
+ /**
9
+ * Tag every entry this logger builds as {@link LogEntry.immediate}
10
+ * (#87). Set only for the logger the console interceptor routes
11
+ * `console.*` calls through; direct application logging leaves this
12
+ * `false` and keeps the existing buffered behavior.
13
+ */
14
+ immediate = false) {
8
15
  Object.defineProperty(this, "manager", {
9
16
  enumerable: true,
10
17
  configurable: true,
@@ -23,6 +30,12 @@ export class ContextLogger {
23
30
  writable: true,
24
31
  value: minLevel
25
32
  });
33
+ Object.defineProperty(this, "immediate", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: immediate
38
+ });
26
39
  Object.defineProperty(this, "timers", {
27
40
  enumerable: true,
28
41
  configurable: true,
@@ -76,10 +89,13 @@ export class ContextLogger {
76
89
  context: { ...this.context },
77
90
  metadata,
78
91
  };
92
+ if (this.immediate) {
93
+ entry.immediate = true;
94
+ }
79
95
  this.manager.dispatch(entry);
80
96
  }
81
97
  child(context) {
82
- return new ContextLogger(this.manager, { ...this.context, ...context }, this.minLevel);
98
+ return new ContextLogger(this.manager, { ...this.context, ...context }, this.minLevel, this.immediate);
83
99
  }
84
100
  scoped(context, fn) {
85
101
  const scopedLogger = this.child(context);
@@ -1,4 +1,4 @@
1
- import type { ILogManager, ILogger, ILogTransport, LogLevel, LogContext, LogEntry, LogManagerConfig, TransportConfig } from '../../api/index.js';
1
+ import type { ILogManager, ILogger, ILogTransport, LogLevel, LogContext, LogEntry, LogManagerConfig, TransportConfig, CreateLoggerOptions } from '../../api/index.js';
2
2
  /**
3
3
  * Central log manager implementation
4
4
  *
@@ -17,7 +17,7 @@ export declare class LogManager implements ILogManager {
17
17
  unregisterTransport(id: string): void;
18
18
  getTransport(id: string): ILogTransport | undefined;
19
19
  listTransports(): ILogTransport[];
20
- createLogger(context?: LogContext): ILogger;
20
+ createLogger(context?: LogContext, options?: CreateLoggerOptions): ILogger;
21
21
  getLogger(context?: LogContext): ILogger;
22
22
  setGlobalLevel(level: LogLevel): void;
23
23
  setPluginLevel(plugin: string, level: LogLevel): void;
@@ -27,6 +27,19 @@ export declare class LogManager implements ILogManager {
27
27
  on(event: 'log' | 'error' | 'flush', handler: (...args: any[]) => void): void;
28
28
  off(event: string, handler: (...args: any[]) => void): void;
29
29
  dispatch(entry: LogEntry): void;
30
+ /**
31
+ * Dispatch a record that bypasses the buffer entirely (#87 — currently only
32
+ * records from the console interceptor).
33
+ *
34
+ * If buffered (non-immediate) records are already pending, flush them
35
+ * first: `flush()` synchronously dispatches every buffered entry to
36
+ * synchronous transports before this method calls `dispatchToTransports`
37
+ * for the new entry, so transports see records in the same order the
38
+ * application produced them — a `logger.info()` call that happened earlier
39
+ * still reaches transports before a `console.log()` that happens after it,
40
+ * even though the logger call is normally deferred to the next flush.
41
+ */
42
+ private dispatchImmediate;
30
43
  /**
31
44
  * Clean up resources
32
45
  */
@@ -1 +1 @@
1
- {"version":3,"file":"log-manager.d.ts","sourceRoot":"","sources":["../../../src/impl/core/log-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,W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,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAIrC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAIrD,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA2B5B,WAAW,IAAI,IAAI;IAInB,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAI7E,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAI3D,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IA6B/B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,iBAAiB;IAczB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAoBhB,oBAAoB;IAyBlC,OAAO,CAAC,cAAc;IA8CtB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,oBAAoB;CAa7B"}
@@ -93,9 +93,9 @@ export class LogManager {
93
93
  listTransports() {
94
94
  return Array.from(this.transports.values());
95
95
  }
96
- createLogger(context) {
96
+ createLogger(context, options) {
97
97
  const level = this.resolveLevel(context);
98
- return new ContextLogger(this, context, level);
98
+ return new ContextLogger(this, context, level, options?.immediate ?? false);
99
99
  }
100
100
  getLogger(context) {
101
101
  const key = this.createCacheKey(context);
@@ -144,6 +144,14 @@ export class LogManager {
144
144
  this.eventEmitter.off(event, handler);
145
145
  }
146
146
  dispatch(entry) {
147
+ // Records from the console interceptor (#87) bypass the buffer entirely
148
+ // instead of following the buffered/immediate-dispatch-for-ERROR rules
149
+ // below: a console.log call is expected to reach transports right away,
150
+ // not up to flushInterval late or lost on an early process exit.
151
+ if (entry.immediate) {
152
+ this.dispatchImmediate(entry);
153
+ return;
154
+ }
147
155
  this.buffer.push(entry);
148
156
  this.eventEmitter.emit('log', entry);
149
157
  // Immediate dispatch for high-priority logs
@@ -159,6 +167,29 @@ export class LogManager {
159
167
  });
160
168
  }
161
169
  }
170
+ /**
171
+ * Dispatch a record that bypasses the buffer entirely (#87 — currently only
172
+ * records from the console interceptor).
173
+ *
174
+ * If buffered (non-immediate) records are already pending, flush them
175
+ * first: `flush()` synchronously dispatches every buffered entry to
176
+ * synchronous transports before this method calls `dispatchToTransports`
177
+ * for the new entry, so transports see records in the same order the
178
+ * application produced them — a `logger.info()` call that happened earlier
179
+ * still reaches transports before a `console.log()` that happens after it,
180
+ * even though the logger call is normally deferred to the next flush.
181
+ */
182
+ dispatchImmediate(entry) {
183
+ if (this.buffer.length > 0) {
184
+ this.flush().catch(error => {
185
+ safeConsole.error('[LogManager] Error flushing buffer:', error);
186
+ });
187
+ }
188
+ this.eventEmitter.emit('log', entry);
189
+ this.dispatchToTransports(entry).catch(error => {
190
+ safeConsole.error('[LogManager] Error dispatching log entry:', error);
191
+ });
192
+ }
162
193
  /**
163
194
  * Clean up resources
164
195
  */
@@ -1 +1 @@
1
- {"version":3,"file":"console-interceptor.d.ts","sourceRoot":"","sources":["../../../src/impl/utils/console-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA0B/D;;;;;;;;;GASG;AACH,qBAAa,kBAAkB;IAiBjB,OAAO,CAAC,UAAU;IAhB9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,CAAc;IAE7B,OAAO,CAAC,cAAc,CAAS;gBAEX,UAAU,EAAE,WAAW;IAE3C;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;IACH,SAAS,IAAI,IAAI;IA0EjB;;;;;;;;;;;;;;OAcG;IACH,OAAO,IAAI,IAAI;IAmCf;;;;OAIG;IACH,kBAAkB,IAAI,WAAW;IAIjC;;OAEG;IACH,OAAO,CAAC,aAAa;CAiBtB"}
1
+ {"version":3,"file":"console-interceptor.d.ts","sourceRoot":"","sources":["../../../src/impl/utils/console-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA0B/D;;;;;;;;;GASG;AACH,qBAAa,kBAAkB;IAiBjB,OAAO,CAAC,UAAU;IAhB9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,CAAc;IAE7B,OAAO,CAAC,cAAc,CAAS;gBAEX,UAAU,EAAE,WAAW;IAE3C;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;IACH,SAAS,IAAI,IAAI;IAgFjB;;;;;;;;;;;;;;OAcG;IACH,OAAO,IAAI,IAAI;IAmCf;;;;OAIG;IACH,kBAAkB,IAAI,WAAW;IAIjC;;OAEG;IACH,OAAO,CAAC,aAAa;CAiBtB"}
@@ -74,10 +74,13 @@ export class ConsoleInterceptor {
74
74
  }
75
75
  // Snapshot before patching, so `restore()` is an exact undo.
76
76
  const previous = this.snapshotConsole();
77
+ // Immediate (#87): an application's console.log is expected to reach
78
+ // transports right away, not wait up to flushInterval for the next
79
+ // flush and risk being lost if the process exits first.
77
80
  const logger = this.logManager.createLogger({
78
81
  plugin: 'console-interceptor',
79
82
  module: 'global'
80
- });
83
+ }, { immediate: true });
81
84
  const record = { patched: {}, previous, retired: false };
82
85
  /**
83
86
  * A patched method, which stops logging once this interceptor has
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamak/logging",
3
- "version": "0.14.2",
3
+ "version": "0.16.0",
4
4
  "description": "Pluggable logging system with API, SPI, and implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -57,8 +57,8 @@
57
57
  "author": "",
58
58
  "license": "MIT",
59
59
  "dependencies": {
60
- "@hamak/microkernel-api": "^0.14.2",
61
- "@hamak/microkernel-spi": "^0.14.2"
60
+ "@hamak/microkernel-api": "^0.16.0",
61
+ "@hamak/microkernel-spi": "^0.16.0"
62
62
  },
63
63
  "devDependencies": {
64
64
  "typescript": "^5.9.3",