@@ -32,15 +32,18 @@ function Core(options) {
32
32
33
33
// set the logger instance
34
34
Logger . setInstance ( new ( options . loggerClass ) ( ) ) ;
35
+ Logger . getInstance ( ) . trace ( 'Logger was initialized.' ) ;
35
36
36
37
// if a connection class is specified, it must be an object or function
37
38
let connectionClass = options . connectionClass ;
38
39
if ( Util . exists ( connectionClass ) ) {
39
40
Errors . assertInternal (
40
41
Util . isObject ( connectionClass ) || Util . isFunction ( connectionClass ) ) ;
42
+ Logger . getInstance ( ) . debug ( 'Connection class provided in driver core options will be used.' ) ;
41
43
} else {
42
44
// fall back to Connection
43
45
connectionClass = Connection ;
46
+ Logger . getInstance ( ) . debug ( 'Connection class was not overridden. Default connection class will be used.' ) ;
44
47
}
45
48
46
49
const qaMode = options . qaMode ;
@@ -64,27 +67,38 @@ function Core(options) {
64
67
// Alternatively, if the connectionOptions includes token information then we will use that
65
68
// instead of the username/password
66
69
70
+ Logger . getInstance ( ) . info ( 'Creating new connection object' ) ;
71
+
67
72
if ( connectionOptions == null ) {
73
+ Logger . getInstance ( ) . info ( 'Connection options were not specified. Loading connection configuration.' ) ;
68
74
try {
69
75
connectionOptions = loadConnectionConfiguration ( ) ;
70
76
} catch ( error ) {
71
- Logger . getInstance ( ) . debug ( `Problem during reading connection configuration from file: ${ error . message } ` ) ;
77
+ Logger . getInstance ( ) . error ( 'Unable to load the connection configuration. Error: %s' , error . message ) ;
72
78
Errors . checkArgumentExists ( Util . exists ( connectionOptions ) ,
73
79
ErrorCodes . ERR_CONN_CREATE_MISSING_OPTIONS ) ;
74
80
}
75
81
}
76
82
77
83
const validateCredentials = ! config && ( connectionOptions && ! connectionOptions . sessionToken ) ;
84
+
78
85
const connectionConfig =
79
86
new ConnectionConfig ( connectionOptions , validateCredentials , qaMode , clientInfo ) ;
87
+ Logger . getInstance ( ) . debug ( 'Connection configuration object created' ) ;
80
88
81
89
// if an http client was specified in the options passed to the module, use
82
90
// it, otherwise create a new HttpClient
83
91
const httpClient = options . httpClient ||
84
92
new options . httpClientClass ( connectionConfig ) ;
93
+ Logger . getInstance ( ) . debug ( 'HttpClient setup finished' ) ;
94
+
85
95
86
- return new connectionClass (
87
- new ConnectionContext ( connectionConfig , httpClient , config ) ) ;
96
+ const connection = new connectionClass (
97
+ new ConnectionContext ( connectionConfig , httpClient , config )
98
+ ) ;
99
+
100
+ Logger . getInstance ( ) . info ( 'Connection[id: %s] - connection object created successfully.' , connection . getId ( ) ) ;
101
+ return connection ;
88
102
} ;
89
103
90
104
const instance =
@@ -124,13 +138,17 @@ function Core(options) {
124
138
*/
125
139
deserializeConnection : function ( options , serializedConnection ) {
126
140
// check for missing serializedConfig
141
+ Logger . getInstance ( ) . trace ( 'Deserializing connection' ) ;
142
+
127
143
Errors . checkArgumentExists ( Util . exists ( serializedConnection ) ,
128
144
ErrorCodes . ERR_CONN_DESERIALIZE_MISSING_CONFIG ) ;
129
145
130
146
// check for invalid serializedConfig
131
147
Errors . checkArgumentValid ( Util . isString ( serializedConnection ) ,
132
148
ErrorCodes . ERR_CONN_DESERIALIZE_INVALID_CONFIG_TYPE ) ;
133
149
150
+ Logger . getInstance ( ) . debug ( 'Deserializing connection from string object' ) ;
151
+
134
152
// try to json-parse serializedConfig
135
153
let config ;
136
154
try {
@@ -140,6 +158,7 @@ function Core(options) {
140
158
Errors . checkArgumentValid ( Util . isObject ( config ) ,
141
159
ErrorCodes . ERR_CONN_DESERIALIZE_INVALID_CONFIG_FORM ) ;
142
160
}
161
+ Logger . getInstance ( ) . debug ( 'Connection deserialized successfully' ) ;
143
162
144
163
return createConnection ( options , config ) ;
145
164
} ,
@@ -152,6 +171,7 @@ function Core(options) {
152
171
* @returns {String } a serialized version of the connection.
153
172
*/
154
173
serializeConnection : function ( connection ) {
174
+ Logger . getInstance ( ) . trace ( 'Connection[id: %s] - serializing connection.' , connection . getId ( ) ) ;
155
175
return connection ? connection . serialize ( ) : connection ;
156
176
} ,
157
177
@@ -161,11 +181,13 @@ function Core(options) {
161
181
* @param {Object } options
162
182
*/
163
183
configure : function ( options ) {
184
+ Logger . getInstance ( ) . debug ( 'Configuring Snowflake core module.' ) ;
164
185
const logLevel = extractLogLevel ( options ) ;
165
186
const logFilePath = options . logFilePath ;
166
187
const additionalLogToConsole = options . additionalLogToConsole ;
188
+
167
189
if ( logLevel != null || logFilePath ) {
168
- Logger . getInstance ( ) . debug ( ` Configuring logger with level: ${ logLevel } , filePath: ${ logFilePath } , additionalLogToConsole: ${ additionalLogToConsole } ` ) ;
190
+ Logger . getInstance ( ) . info ( ' Configuring logger with level: %s , filePath: %s , additionalLogToConsole: %s' , logLevel , logFilePath , additionalLogToConsole ) ;
169
191
Logger . getInstance ( ) . configure (
170
192
{
171
193
level : logLevel ,
@@ -181,6 +203,7 @@ function Core(options) {
181
203
ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_INSECURE_CONNECT ) ;
182
204
183
205
GlobalConfig . setInsecureConnect ( insecureConnect ) ;
206
+ Logger . getInstance ( ) . debug ( 'Setting insecureConnect to value from core options: %s' , insecureConnect ) ;
184
207
}
185
208
186
209
const ocspFailOpen = options . ocspFailOpen ;
@@ -189,6 +212,7 @@ function Core(options) {
189
212
ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_OCSP_MODE ) ;
190
213
191
214
GlobalConfig . setOcspFailOpen ( ocspFailOpen ) ;
215
+ Logger . getInstance ( ) . debug ( 'Setting ocspFailOpen to value from core options: %s ' , ocspFailOpen ) ;
192
216
}
193
217
194
218
const jsonColumnVariantParser = options . jsonColumnVariantParser ;
@@ -197,6 +221,7 @@ function Core(options) {
197
221
ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_JSON_PARSER ) ;
198
222
199
223
GlobalConfig . setJsonColumnVariantParser ( jsonColumnVariantParser ) ;
224
+ Logger . getInstance ( ) . debug ( 'Setting JSON Column Variant Parser to value from core options' ) ;
200
225
}
201
226
202
227
const xmlColumnVariantParser = options . xmlColumnVariantParser ;
@@ -206,8 +231,10 @@ function Core(options) {
206
231
ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_XML_PARSER ) ;
207
232
208
233
GlobalConfig . setXmlColumnVariantParser ( xmlColumnVariantParser ) ;
234
+ Logger . getInstance ( ) . debug ( 'Setting XML Column Variant Parser to value from core options' ) ;
209
235
} else if ( Util . exists ( xmlParserConfig ) ) {
210
236
GlobalConfig . createXmlColumnVariantParserWithParameters ( xmlParserConfig ) ;
237
+ Logger . getInstance ( ) . debug ( 'Creating XML Column Variant Parser with parameters from core options' ) ;
211
238
}
212
239
213
240
const keepAlive = options . keepAlive ;
@@ -216,6 +243,7 @@ function Core(options) {
216
243
ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_KEEP_ALIVE ) ;
217
244
218
245
GlobalConfig . setKeepAlive ( keepAlive ) ;
246
+ Logger . getInstance ( ) . debug ( 'Setting keepAlive to value from core options: %s' , keepAlive ) ;
219
247
}
220
248
221
249
const useEnvProxy = options . useEnvProxy ;
@@ -232,7 +260,8 @@ function Core(options) {
232
260
ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_CUSTOM_CREDENTIAL_MANAGER ) ;
233
261
234
262
GlobalConfig . setCustomCredentialManager ( customCredentialManager ) ;
235
- }
263
+ Logger . getInstance ( ) . debug ( 'Setting customCredentialManager to value from core options %s' , customCredentialManager ) ;
264
+ }
236
265
}
237
266
} ;
238
267
@@ -275,15 +304,17 @@ function Core(options) {
275
304
* @returns {Object }
276
305
*/
277
306
this . create = function ( ) {
307
+ Logger . getInstance ( ) . debug ( 'Creating new connection from factory.' ) ;
278
308
const connection = new createConnection ( connectionOptions ) ;
279
309
280
310
return new Promise ( ( resolve , reject ) => {
281
311
connection . connect (
282
312
function ( err , conn ) {
283
313
if ( err ) {
284
- Logger . getInstance ( ) . error ( 'Unable to connect: ' + err . message ) ;
314
+ Logger . getInstance ( ) . error ( 'Connection[id: %s] - Unable to connect. Error: %s' , conn . getId ( ) , err . message ) ;
285
315
reject ( new Error ( err . message ) ) ;
286
316
} else {
317
+ Logger . getInstance ( ) . debug ( 'Connection[id: %s] - connected successfully. Callback called.' , conn . getId ( ) ) ;
287
318
resolve ( conn ) ;
288
319
}
289
320
}
@@ -299,10 +330,13 @@ function Core(options) {
299
330
* @returns {Object }
300
331
*/
301
332
this . destroy = function ( connection ) {
333
+ Logger . getInstance ( ) . debug ( 'Destroying connection instance.' ) ;
302
334
return new Promise ( ( resolve ) => {
303
- connection . destroy ( function ( err ) {
335
+ connection . destroy ( function ( err , conn ) {
304
336
if ( err ) {
305
- Logger . getInstance ( ) . error ( 'Unable to disconnect: ' + err . message ) ;
337
+ Logger . getInstance ( ) . error ( 'Connection[id: %s] - disconnecting failed with error: %s' , conn . getId ( ) , err . message ) ;
338
+ } else {
339
+ Logger . getInstance ( ) . debug ( 'Connection[id: %s] - connection disconnected successfully. Callback called.' , conn . getId ( ) ) ;
306
340
}
307
341
resolve ( ) ;
308
342
} ) ;
@@ -317,6 +351,7 @@ function Core(options) {
317
351
* @returns {Boolean }
318
352
*/
319
353
this . validate = async function ( connection ) {
354
+ Logger . getInstance ( ) . debug ( 'Connection[id: %s] - validating connection instance' , connection . getId ( ) ) ;
320
355
return await connection . isValidAsync ( ) ;
321
356
} ;
322
357
}
@@ -330,19 +365,25 @@ function Core(options) {
330
365
* @returns {Object }
331
366
*/
332
367
const createPool = function createPool ( connectionOptions , poolOptions ) {
368
+ Logger . getInstance ( ) . info ( 'Creating connection pool with provided options' ) ;
369
+
333
370
const connectionPool = GenericPool . createPool (
334
371
new ConnectionFactory ( connectionOptions ) ,
335
372
poolOptions
336
373
) ;
374
+ Logger . getInstance ( ) . debug ( 'Base for connection pool created' ) ;
337
375
338
376
// avoid infinite loop if factory creation fails
339
377
connectionPool . on ( 'factoryCreateError' , function ( err ) {
378
+ Logger . getInstance ( ) . error ( 'Connection pool factory creation failed: %s' , err . message ) ;
340
379
const clientResourceRequest = connectionPool . _waitingClientsQueue . dequeue ( ) ;
341
380
if ( clientResourceRequest ) {
342
381
clientResourceRequest . reject ( err ) ;
343
382
}
344
383
} ) ;
345
384
385
+ Logger . getInstance ( ) . info ( 'Connection pool object created successfully' ) ;
386
+
346
387
return connectionPool ;
347
388
} ;
348
389
0 commit comments