1818 */ 
1919
2020import  {  Chunker ,  Dechunker ,  ChannelConfig ,  Channel  }  from  '../channel' 
21- import  {  newError ,  error ,  json  }  from  'neo4j-driver-core' 
21+ import  {  newError ,  error ,  json ,   internal  }  from  'neo4j-driver-core' 
2222import  Connection  from  './connection' 
2323import  Bolt  from  '../bolt' 
2424
2525const  {  PROTOCOL_ERROR  }  =  error 
26+ const  { 
27+   logger : {  Logger } 
28+ }  =  internal 
2629
2730let  idGenerator  =  0 
2831
@@ -57,15 +60,14 @@ export function createChannelConnection (
5760      const  createProtocol  =  conn  => 
5861        Bolt . create ( { 
5962          version, 
60-           connection : conn , 
6163          channel, 
6264          chunker, 
6365          dechunker, 
6466          disableLosslessIntegers : config . disableLosslessIntegers , 
6567          useBigInt : config . useBigInt , 
6668          serversideRouting, 
6769          server : conn . server , 
68-           log, 
70+           log :  conn . logger , 
6971          observer : { 
7072            onError : conn . _handleFatalError . bind ( conn ) , 
7173            onFailure : conn . _resetOnFailure . bind ( conn ) , 
@@ -97,7 +99,6 @@ export function createChannelConnection (
9799      } ) 
98100    ) 
99101} 
100- 
101102export  default  class  ChannelConnection  extends  Connection  { 
102103  /** 
103104   * @constructor  
@@ -128,7 +129,7 @@ export default class ChannelConnection extends Connection {
128129    this . _disableLosslessIntegers  =  disableLosslessIntegers 
129130    this . _ch  =  channel 
130131    this . _chunker  =  chunker 
131-     this . _log  =  log 
132+     this . _log  =  createConnectionLogger ( this ,   log ) 
132133    this . _serversideRouting  =  serversideRouting 
133134
134135    // connection from the database, returned in response for HELLO message and might not be available 
@@ -145,7 +146,7 @@ export default class ChannelConnection extends Connection {
145146    this . _isBroken  =  false 
146147
147148    if  ( this . _log . isDebugEnabled ( ) )  { 
148-       this . _log . debug ( `${ this }   created towards ${ address }  ` ) 
149+       this . _log . debug ( `created towards ${ address }  ` ) 
149150    } 
150151  } 
151152
@@ -234,6 +235,10 @@ export default class ChannelConnection extends Connection {
234235    return  this . _server 
235236  } 
236237
238+   get  logger  ( )  { 
239+     return  this . _log 
240+   } 
241+ 
237242  /** 
238243   * "Fatal" means the connection is dead. Only call this if something 
239244   * happens that cannot be recovered from. This will lead to all subscribers 
@@ -247,7 +252,7 @@ export default class ChannelConnection extends Connection {
247252
248253    if  ( this . _log . isErrorEnabled ( ) )  { 
249254      this . _log . error ( 
250-         `${ this }   experienced a fatal error ${ json . stringify ( this . _error ) }  ` 
255+         `experienced a fatal error ${ json . stringify ( this . _error ) }  ` 
251256      ) 
252257    } 
253258
@@ -322,7 +327,7 @@ export default class ChannelConnection extends Connection {
322327   */ 
323328  async  close  ( )  { 
324329    if  ( this . _log . isDebugEnabled ( ) )  { 
325-       this . _log . debug ( ` ${ this }   closing` ) 
330+       this . _log . debug ( ' closing' ) 
326331    } 
327332
328333    if  ( this . _protocol  &&  this . isOpen ( ) )  { 
@@ -334,7 +339,7 @@ export default class ChannelConnection extends Connection {
334339    await  this . _ch . close ( ) 
335340
336341    if  ( this . _log . isDebugEnabled ( ) )  { 
337-       this . _log . debug ( ` ${ this }   closed` ) 
342+       this . _log . debug ( ' closed' ) 
338343    } 
339344  } 
340345
@@ -350,3 +355,15 @@ export default class ChannelConnection extends Connection {
350355    return  error 
351356  } 
352357} 
358+ 
359+ /** 
360+  * Creates a log with the connection info as prefix 
361+  * @param  {Connection } connection The connection 
362+  * @param  {Logger } logger The logger 
363+  * @returns  {Logger } The new logger with enriched messages 
364+  */ 
365+ function  createConnectionLogger  ( connection ,  logger )  { 
366+   return  new  Logger ( logger . _level ,  ( level ,  message )  => 
367+     logger . _loggerFunction ( level ,  `${ connection }   ${ message }  ` ) 
368+   ) 
369+ } 
0 commit comments