Skip to content

Commit f2955bc

Browse files
Make default logger singleton (#199)
Signed-off-by: Levko Kravets <[email protected]>
1 parent e494e74 commit f2955bc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/DBSQLClient.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function getInitialNamespaceOptions(catalogName?: string, schemaName?: string) {
4444
}
4545

4646
export default class DBSQLClient extends EventEmitter implements IDBSQLClient, IClientContext {
47+
private static defaultLogger?: IDBSQLLogger;
48+
4749
private connectionProvider?: IConnectionProvider;
4850

4951
private authProvider?: IAuthentication;
@@ -60,9 +62,16 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
6062

6163
private sessions = new CloseableCollection<DBSQLSession>();
6264

65+
private static getDefaultLogger(): IDBSQLLogger {
66+
if (!this.defaultLogger) {
67+
this.defaultLogger = new DBSQLLogger();
68+
}
69+
return this.defaultLogger;
70+
}
71+
6372
constructor(options?: ClientOptions) {
6473
super();
65-
this.logger = options?.logger || new DBSQLLogger();
74+
this.logger = options?.logger ?? DBSQLClient.getDefaultLogger();
6675
this.logger.log(LogLevel.info, 'Created DBSQLClient');
6776
}
6877

0 commit comments

Comments
 (0)