Skip to content

Commit

Permalink
Make default logger singleton (#199)
Browse files Browse the repository at this point in the history
Signed-off-by: Levko Kravets <[email protected]>
  • Loading branch information
kravets-levko authored Oct 26, 2023
1 parent e494e74 commit f2955bc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,9 +62,16 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I

private sessions = new CloseableCollection<DBSQLSession>();

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');
}

Expand Down

0 comments on commit f2955bc

Please sign in to comment.