Skip to content

Commit 63199f4

Browse files
committed
fix: fixed memory leak where all child loggers formed a object group
Keeping track of children held a strong reference across whole logger tree. It means that a single reference held all the children in memory. [ci skip]
1 parent fc3b73d commit 63199f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Logger {
1111
public readonly keys: string;
1212
public readonly handlers: Set<Handler>;
1313
public readonly parent?: Logger;
14-
public readonly loggers: { [key: string]: Logger } = {};
14+
public readonly loggers: Set<string> = new Set();
1515

1616
constructor(
1717
key: string = 'root',
@@ -27,11 +27,11 @@ class Logger {
2727
}
2828

2929
public getChild(key: string): Logger {
30-
if (this.loggers[key]) {
31-
return this.loggers[key];
30+
if (this.loggers.has(key)) {
31+
throw Error('cannot have duplicate child keys');
3232
}
3333
const logger = new Logger(key, LogLevel.NOTSET, [], this);
34-
this.loggers[key] = logger;
34+
this.loggers.add(key);
3535
return logger;
3636
}
3737

0 commit comments

Comments
 (0)