diff --git a/src/main/ts/log/Registry.ts b/src/main/ts/log/Registry.ts --- a/src/main/ts/log/Registry.ts +++ b/src/main/ts/log/Registry.ts @@ -14,12 +14,12 @@ export class Registry { if (this._registry[id]) return this._registry[id]; + else + throw new Error("The specified trace source doesn't exists"); + } - const source = new TraceSource(id); - this._registry[id] = source; - this._onNewSource(source); - - return source; + has(id: string) { + return !!this._registry[id]; } add(id: any, source: TraceSource) { diff --git a/src/main/ts/log/TraceSource.ts b/src/main/ts/log/TraceSource.ts --- a/src/main/ts/log/TraceSource.ts +++ b/src/main/ts/log/TraceSource.ts @@ -136,6 +136,12 @@ export class TraceSource { * @param id the id for the trace source */ static get(id: any) { - return Registry.instance.get(id); + if (!Registry.instance.has(id)) { + const trace = new TraceSource(id); + Registry.instance.add(id, trace); + return trace; + } else { + return Registry.instance.get(id); + } } }