Skip to content

Commit c29dd1a

Browse files
committed
refactor: delete singleton
1 parent 2e7f020 commit c29dd1a

File tree

2 files changed

+12
-57
lines changed

2 files changed

+12
-57
lines changed

src/logger/__tests__/index.test.mjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/logger/index.mjs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,20 @@ import { transports } from './transports/index.mjs';
88
*/
99

1010
/**
11-
* Singleton logger instance for consistent logging across the app.
11+
* Creates a new logger instance with the specified transport.
12+
*
13+
* @param {string} [transportName='console'] - Name of the transport to use.
14+
* @returns {LoggerInstance}
1215
*/
13-
export const Logger = (() => {
14-
/**
15-
* @type {LoggerInstance}
16-
*/
17-
let instance;
16+
export const Logger = (transportName = 'console') => {
17+
const transport = transports[transportName];
1818

19-
/**
20-
* Inits the logger with the specified transport.
21-
*
22-
* @param {string} [transportName]
23-
* @returns {LoggerInstance}
24-
*/
25-
function init(transportName = 'console') {
26-
const transport = transports[transportName];
27-
28-
if (!transport) {
29-
throw new Error(`Transport '${transportName}' not found.`);
30-
}
31-
32-
instance = createLogger(transport);
33-
return instance;
34-
}
35-
36-
/**
37-
* Returns the singleton logger instance.
38-
*
39-
* @returns {LoggerInstance}
40-
*/
41-
function getInstance() {
42-
if (!instance) {
43-
throw new Error(
44-
'Logger not initialized. Call Logger.init(transportName) first.'
45-
);
46-
}
47-
48-
return instance;
19+
if (!transport) {
20+
throw new Error(`Transport '${transportName}' not found.`);
4921
}
5022

51-
return {
52-
init,
53-
getInstance,
54-
};
55-
})();
23+
return createLogger(transport);
24+
};
5625

57-
export default Logger.init();
26+
// Default logger instance using console transport
27+
export default Logger();

0 commit comments

Comments
 (0)