From 0c8d698695b8fe1e614cc7bbadc90a7ce7b110e5 Mon Sep 17 00:00:00 2001 From: Levko Kravets Date: Tue, 24 Oct 2023 13:34:50 +0300 Subject: [PATCH] Make default logger singleton Signed-off-by: Levko Kravets --- lib/DBSQLClient.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/DBSQLClient.ts b/lib/DBSQLClient.ts index b331c81e..6d5b8bbd 100644 --- a/lib/DBSQLClient.ts +++ b/lib/DBSQLClient.ts @@ -44,6 +44,8 @@ function getInitialNamespaceOptions(catalogName?: string, schemaName?: string) { } export default class DBSQLClient extends EventEmitter implements IDBSQLClient, IClientContext { + private static defaultLogger?: IDBSQLLogger; + private connectionProvider?: IConnectionProvider; private authProvider?: IAuthentication; @@ -60,9 +62,16 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I private sessions = new CloseableCollection(); + private static getDefaultLogger(): IDBSQLLogger { + if (!this.defaultLogger) { + this.defaultLogger = new DBSQLLogger(); + } + return this.defaultLogger; + } + constructor(options?: ClientOptions) { super(); - this.logger = options?.logger || new DBSQLLogger(); + this.logger = options?.logger ?? DBSQLClient.getDefaultLogger(); this.logger.log(LogLevel.info, 'Created DBSQLClient'); }