@@ -281,9 +281,7 @@ func (c *Conn) checkBadConn(ctx context.Context, err error, mayRetry bool) error
281281 }
282282
283283 if ! c .connectionGood && mayRetry && ! c .connector .params .DisableRetry {
284- if c .sess .logFlags & logRetries != 0 {
285- c .sess .logger .Log (ctx , msdsn .LogRetries , err .Error ())
286- }
284+ c .sess .Log (ctx , msdsn .LogRetries , err .Error )
287285 return newRetryableError (err )
288286 }
289287
@@ -324,9 +322,7 @@ func (c *Conn) sendCommitRequest() error {
324322 reset := c .resetSession
325323 c .resetSession = false
326324 if err := sendCommitXact (c .sess .buf , headers , "" , 0 , 0 , "" , reset ); err != nil {
327- if c .sess .logFlags & logErrors != 0 {
328- c .sess .logger .Log (c .transactionCtx , msdsn .LogErrors , fmt .Sprintf ("Failed to send CommitXact with %v" , err ))
329- }
325+ c .sess .LogF (c .transactionCtx , msdsn .LogErrors , "Failed to send CommitXact with %v" , err )
330326 c .connectionGood = false
331327 return fmt .Errorf ("faild to send CommitXact: %v" , err )
332328 }
@@ -351,9 +347,7 @@ func (c *Conn) sendRollbackRequest() error {
351347 reset := c .resetSession
352348 c .resetSession = false
353349 if err := sendRollbackXact (c .sess .buf , headers , "" , 0 , 0 , "" , reset ); err != nil {
354- if c .sess .logFlags & logErrors != 0 {
355- c .sess .logger .Log (c .transactionCtx , msdsn .LogErrors , fmt .Sprintf ("Failed to send RollbackXact with %v" , err ))
356- }
350+ c .sess .LogF (c .transactionCtx , msdsn .LogErrors , "Failed to send RollbackXact with %v" , err )
357351 c .connectionGood = false
358352 return fmt .Errorf ("failed to send RollbackXact: %v" , err )
359353 }
@@ -388,9 +382,7 @@ func (c *Conn) sendBeginRequest(ctx context.Context, tdsIsolation isoLevel) erro
388382 reset := c .resetSession
389383 c .resetSession = false
390384 if err := sendBeginXact (c .sess .buf , headers , tdsIsolation , "" , reset ); err != nil {
391- if c .sess .logFlags & logErrors != 0 {
392- c .sess .logger .Log (ctx , msdsn .LogErrors , fmt .Sprintf ("Failed to send BeginXact with %v" , err ))
393- }
385+ c .sess .LogF (ctx , msdsn .LogErrors , "Failed to send BeginXact with %v" , err )
394386 c .connectionGood = false
395387 return fmt .Errorf ("failed to send BeginXact: %v" , err )
396388 }
@@ -524,15 +516,13 @@ func (s *Stmt) sendQuery(ctx context.Context, args []namedValue) (err error) {
524516 conn := s .c
525517
526518 // no need to check number of parameters here, it is checked by database/sql
527- if conn .sess .logFlags & logSQL != 0 {
528- conn .sess .logger .Log (ctx , msdsn .LogSQL , s .query )
529- }
519+ conn .sess .LogS (ctx , msdsn .LogSQL , s .query )
530520 if conn .sess .logFlags & logParams != 0 && len (args ) > 0 {
531521 for i := 0 ; i < len (args ); i ++ {
532522 if len (args [i ].Name ) > 0 {
533- s .c .sess .logger . Log (ctx , msdsn .LogParams , fmt . Sprintf ( "\t @%s\t %v" , args [i ].Name , args [i ].Value ) )
523+ s .c .sess .LogF (ctx , msdsn .LogParams , "\t @%s\t %v" , args [i ].Name , args [i ].Value )
534524 } else {
535- s .c .sess .logger . Log (ctx , msdsn .LogParams , fmt . Sprintf ( "\t @p%d\t %v" , i + 1 , args [i ].Value ) )
525+ s .c .sess .LogF (ctx , msdsn .LogParams , "\t @p%d\t %v" , i + 1 , args [i ].Value )
536526 }
537527 }
538528 }
@@ -542,9 +532,7 @@ func (s *Stmt) sendQuery(ctx context.Context, args []namedValue) (err error) {
542532 isProc := isProc (s .query )
543533 if len (args ) == 0 && ! isProc {
544534 if err = sendSqlBatch72 (conn .sess .buf , s .query , headers , reset ); err != nil {
545- if conn .sess .logFlags & logErrors != 0 {
546- conn .sess .logger .Log (ctx , msdsn .LogErrors , fmt .Sprintf ("Failed to send SqlBatch with %v" , err ))
547- }
535+ conn .sess .LogF (ctx , msdsn .LogErrors , "Failed to send SqlBatch with %v" , err )
548536 conn .connectionGood = false
549537 return fmt .Errorf ("failed to send SQL Batch: %v" , err )
550538 }
@@ -567,9 +555,7 @@ func (s *Stmt) sendQuery(ctx context.Context, args []namedValue) (err error) {
567555 params [1 ] = makeStrParam (strings .Join (decls , "," ))
568556 }
569557 if err = sendRpc (conn .sess .buf , headers , proc , 0 , params , reset ); err != nil {
570- if conn .sess .logFlags & logErrors != 0 {
571- conn .sess .logger .Log (ctx , msdsn .LogErrors , fmt .Sprintf ("Failed to send Rpc with %v" , err ))
572- }
558+ conn .sess .LogF (ctx , msdsn .LogErrors , "Failed to send Rpc with %v" , err )
573559 conn .connectionGood = false
574560 return fmt .Errorf ("failed to send RPC: %v" , err )
575561 }
@@ -1298,9 +1284,7 @@ func (rc *Rowsq) Columns() (res []string) {
12981284 for {
12991285 tok , err := rc .reader .nextToken ()
13001286 if err == nil {
1301- if rc .reader .sess .logFlags & logDebug != 0 {
1302- rc .reader .sess .logger .Log (rc .reader .ctx , msdsn .LogDebug , fmt .Sprintf ("Columns() token type:%v" , reflect .TypeOf (tok )))
1303- }
1287+ rc .reader .sess .LogF (rc .reader .ctx , msdsn .LogDebug , "Columns() token type:%v" , reflect .TypeOf (tok ))
13041288 if tok == nil {
13051289 return []string {}
13061290 } else {
@@ -1327,9 +1311,7 @@ func (rc *Rowsq) Next(dest []driver.Value) error {
13271311 }
13281312 for {
13291313 tok , err := rc .reader .nextToken ()
1330- if rc .reader .sess .logFlags & logDebug != 0 {
1331- rc .reader .sess .logger .Log (rc .reader .ctx , msdsn .LogDebug , fmt .Sprintf ("Next() token type:%v" , reflect .TypeOf (tok )))
1332- }
1314+ rc .reader .sess .LogF (rc .reader .ctx , msdsn .LogDebug , "Next() token type:%v" , reflect .TypeOf (tok ))
13331315 if err == nil {
13341316 if tok == nil {
13351317 return io .EOF
@@ -1391,9 +1373,7 @@ func (rc *Rowsq) NextResultSet() error {
13911373scan:
13921374 for {
13931375 tok , err := rc .reader .nextToken ()
1394- if rc .reader .sess .logFlags & logDebug != 0 {
1395- rc .reader .sess .logger .Log (rc .reader .ctx , msdsn .LogDebug , fmt .Sprintf ("NextResultSet() token type:%v" , reflect .TypeOf (tok )))
1396- }
1376+ rc .reader .sess .LogF (rc .reader .ctx , msdsn .LogDebug , "NextResultSet() token type:%v" , reflect .TypeOf (tok ))
13971377
13981378 if err != nil {
13991379 return err
0 commit comments