From c3532a3f42ac9b7b3ee83793b4b6ec92eeefdec2 Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Wed, 13 Nov 2024 05:40:49 -0500 Subject: [PATCH 1/5] Set more sensible defaults for logger in driver/client and pool. --- src/lib/sql-client.ts | 3 +-- src/lib/sql-pool.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/sql-client.ts b/src/lib/sql-client.ts index 809dbc9..226e9ee 100644 --- a/src/lib/sql-client.ts +++ b/src/lib/sql-client.ts @@ -1,6 +1,5 @@ import * as forge from 'node-forge'; - import { getURIScheme } from './utils'; import { CreatePreparedStatementResponse, PublicKeyResponse, SQLQueriesResponse, SQLResponse } from './types'; import { Statement } from './statement'; @@ -68,7 +67,7 @@ export class ExasolDriver implements IExasolDriver { private readonly pool: ConnectionPool; - constructor(websocketFactory: websocketFactory, config: Partial, logger: ILogger = new Logger(LogLevel.Debug)) { + constructor(websocketFactory: websocketFactory, config: Partial, logger: ILogger = new Logger(LogLevel.Off)) { // Used internally to avoid parallel execution this.pool = new ConnectionPool(1, logger); this.config = { diff --git a/src/lib/sql-pool.ts b/src/lib/sql-pool.ts index 174f4c5..6ffcbcd 100644 --- a/src/lib/sql-pool.ts +++ b/src/lib/sql-pool.ts @@ -56,7 +56,7 @@ export class ExasolPool { constructor( websocketFactory: websocketFactory, config: Partial & Partial, - logger: ILogger = new Logger(LogLevel.Debug), + logger: ILogger = new Logger(LogLevel.Off), ) { this.logger = logger; this.internalPool = getPool(websocketFactory, config, logger); From 56ca9c732de261b498cf13ffb74aa478ac8487c9 Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Wed, 13 Nov 2024 05:41:19 -0500 Subject: [PATCH 2/5] add logger types to index.ts exports --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index f10bd65..e0ef467 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,3 +6,4 @@ export * from './lib/commands'; export * from './lib/sql-client.interface'; export * from './lib/statement'; export * from './lib/connection'; +export * from './lib/logger/logger'; From 64f4adffdf13b0870068bc8f1378fb8545579c7c Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Wed, 13 Nov 2024 05:44:15 -0500 Subject: [PATCH 3/5] fix issue where LogLevel.Off would not correctly be set in the constructor, fixed by using a default in the constructor instead and not doing an 'implicit' check for undefined + gave explicit values to all LogLevel levels. --- src/lib/logger/logger.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/lib/logger/logger.ts b/src/lib/logger/logger.ts index bfed8eb..c14f080 100644 --- a/src/lib/logger/logger.ts +++ b/src/lib/logger/logger.ts @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ export enum LogLevel { Off = 0, - Error, - Warn, - Info, - Debug, - Trace, + Error = 1, + Warn = 2, + Info = 3, + Debug = 4, + Trace = 5, } export type LoggerMethod = (...data: any) => void; @@ -21,10 +21,8 @@ export interface ILogger { export class Logger implements ILogger { private readonly level: LogLevel = LogLevel.Debug; - constructor(level?: number) { - if (level) { - this.level = level; - } + constructor(level: LogLevel = LogLevel.Debug) { + this.level = level; } private readonly emptyLog = () => { @@ -81,7 +79,7 @@ export class Logger implements ILogger { `%c[${new Date().toISOString()}] %c${level}%c: %s`, 'color: gray', 'color: ' + color, - 'color: inherit' + 'color: inherit', ); } } From 5231aee4de81338cfd42d76d48cfba8d3bf870cd Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Wed, 13 Nov 2024 08:17:59 -0500 Subject: [PATCH 4/5] Add tests for logger --- src/lib/logger/logger.spec.ts | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/lib/logger/logger.spec.ts diff --git a/src/lib/logger/logger.spec.ts b/src/lib/logger/logger.spec.ts new file mode 100644 index 0000000..ce2d834 --- /dev/null +++ b/src/lib/logger/logger.spec.ts @@ -0,0 +1,44 @@ +import { LogLevel, Logger } from './logger'; + +describe('Logger', () => { + it('Should "console.log()" with default Log level (= debug) when using logger.debug()', () => { + const defaultLogger = new Logger(); + + const logSpy = jest.spyOn(global.console, 'log'); + defaultLogger.debug('hello'); + expect(logSpy).toHaveBeenCalled(); + }); + it('Should "console.log()" with log level debug when using logger.debug()', () => { + const defaultLogger = new Logger(LogLevel.Debug); + + const logSpy = jest.spyOn(global.console, 'log'); + defaultLogger.debug('hello'); + expect(logSpy).toHaveBeenCalled(); + }); + it('Should not "console.log" with log level "off" when using logger.debug()', () => { + const defaultLogger = new Logger(LogLevel.Off); + + const logSpy = jest.spyOn(global.console, 'log'); + defaultLogger.debug('hello'); + expect(logSpy).not.toHaveBeenCalled(); + }); + it('Should not "console.log" with a lower debug level than debug when using logger.debug()', () => { + const defaultLogger = new Logger(LogLevel.Error); + + const logSpy = jest.spyOn(global.console, 'log'); + defaultLogger.debug('hello'); + expect(logSpy).not.toHaveBeenCalled(); + }); + + it('Should "console.log" with a higher debug level than debug when using logger.debug()', () => { + const defaultLogger = new Logger(LogLevel.Trace); + + const logSpy = jest.spyOn(global.console, 'log'); + defaultLogger.debug('hello'); + expect(logSpy).toHaveBeenCalled(); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); +}); From d83b6ef1fd329af84c494c04909a3dd7fde9f820 Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Wed, 13 Nov 2024 08:34:05 -0500 Subject: [PATCH 5/5] Changes doc --- doc/changes/changes_0.2.0.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/changes/changes_0.2.0.md b/doc/changes/changes_0.2.0.md index 06e8c6d..7d69094 100644 --- a/doc/changes/changes_0.2.0.md +++ b/doc/changes/changes_0.2.0.md @@ -1,14 +1,16 @@ -# Exasol Driver ts 0.2.0, released 2024-??-?? +# Exasol Driver ts 0.2.0, released 2024-11-13 -Code name: TBD +Code name: Connection pool and logging ## Summary Adds `ExasolPool`, which is a connection pool using `ExasolDriver` underneath. See the user guide for a new section on how to configure and use the `ExasolPool` class. +Logging is now configurable for both driver/client and pool. The defaults are now also more sensible (off). An issue with switching off logging was also resolved. ## Features - #28: Add a connection pool. +- #34: Make log level configurable. ## Dependency Updates