|
1 | 1 | const net = require('net'); |
2 | | -const logger = require('pino')({ level: process.env.JAMBONES_LOGLEVEL || 'info' }); |
3 | 2 |
|
4 | 3 | const config = new Map(); |
5 | 4 | const queue = []; |
6 | 5 | let processing = false; |
| 6 | +let logger; |
7 | 7 |
|
8 | 8 | async function runOperation(operation) { |
9 | 9 | return new Promise((resolve, reject) => { |
@@ -31,10 +31,15 @@ async function processQueue() { |
31 | 31 | } |
32 | 32 |
|
33 | 33 | class RuntimeConfig { |
34 | | - constructor(srfLocals = null) { |
| 34 | + constructor(srfLocals = null, appLogger = null) { |
35 | 35 | this.server = null; |
36 | 36 | this.socketPath = process.env.SBC_SOCKET_PATH || '/tmp/sbc-sip-sidecar.sock'; |
37 | 37 | this.srfLocals = srfLocals; |
| 38 | + if (appLogger) { |
| 39 | + logger = appLogger; |
| 40 | + } else if (!logger) { |
| 41 | + throw new Error('Logger is required for RuntimeConfig'); |
| 42 | + } |
38 | 43 | this.startServer(); |
39 | 44 | } |
40 | 45 |
|
@@ -387,32 +392,36 @@ class RuntimeConfig { |
387 | 392 |
|
388 | 393 | let runtimeConfig = null; |
389 | 394 |
|
390 | | -function createInstance(srfLocals = null) { |
391 | | - const instance = new RuntimeConfig(srfLocals); |
| 395 | +function createInstance(srfLocals = null, appLogger = null) { |
| 396 | + const instance = new RuntimeConfig(srfLocals, appLogger); |
392 | 397 | process.on('SIGINT', () => instance.shutdown()); |
393 | 398 | process.on('SIGTERM', () => instance.shutdown()); |
394 | 399 | return instance; |
395 | 400 | } |
396 | 401 |
|
397 | | -function initializeRuntimeConfig(srfLocals) { |
| 402 | +function initialize(srfLocals, appLogger) { |
| 403 | + if (!appLogger) { |
| 404 | + throw new Error('Logger is required for RuntimeConfig initialization'); |
| 405 | + } |
398 | 406 | if (!runtimeConfig) { |
399 | | - runtimeConfig = createInstance(srfLocals); |
| 407 | + runtimeConfig = createInstance(srfLocals, appLogger); |
400 | 408 | } else { |
401 | | - // Update existing instance with srfLocals |
| 409 | + // Update existing instance with srfLocals and logger |
402 | 410 | runtimeConfig.srfLocals = srfLocals; |
| 411 | + logger = appLogger; |
403 | 412 | } |
404 | 413 |
|
405 | 414 | return runtimeConfig; |
406 | 415 | } |
407 | 416 |
|
408 | 417 | function getInstance() { |
409 | 418 | if (!runtimeConfig) { |
410 | | - runtimeConfig = createInstance(); |
| 419 | + throw new Error('RuntimeConfig not initialized. Call initialize() first with logger.'); |
411 | 420 | } |
412 | 421 | return runtimeConfig; |
413 | 422 | } |
414 | 423 |
|
415 | 424 | module.exports = { |
416 | | - initialize: initializeRuntimeConfig, |
| 425 | + initialize, |
417 | 426 | getInstance |
418 | 427 | }; |
0 commit comments