Pārlūkot izejas kodu

removed .Error() in logger, removed mutex to set logger

Arne Hormann 12 gadi atpakaļ
vecāks
revīzija
58ec5b4271
2 mainītis faili ar 13 papildinājumiem un 18 dzēšanām
  1. 2 7
      errors.go
  2. 11 11
      packets.go

+ 2 - 7
errors.go

@@ -15,7 +15,6 @@ import (
 	"io"
 	"log"
 	"os"
-	"sync"
 )
 
 var (
@@ -28,10 +27,8 @@ var (
 	errPktSyncMul  = errors.New("Commands out of sync. Did you run multiple statements at once?")
 	errPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
 	errBusyBuffer  = errors.New("Busy buffer")
-	errNoLogger    = errors.New("logger is nil")
 
-	errLog     Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)
-	errLogLock        = &sync.Mutex{}
+	errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)
 )
 
 // Logger is used to log critical error messages.
@@ -43,11 +40,9 @@ type Logger interface {
 // The initial logger is stderr.
 func SetLogger(logger Logger) error {
 	if logger == nil {
-		return errNoLogger
+		return errors.New("logger is nil")
 	}
-	errLogLock.Lock()
 	errLog = logger
-	errLogLock.Unlock()
 	return nil
 }
 

+ 11 - 11
packets.go

@@ -29,7 +29,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
 		// Read packet header
 		data, err := mc.buf.readNext(4)
 		if err != nil {
-			errLog.Print(err.Error())
+			errLog.Print(err)
 			mc.Close()
 			return nil, driver.ErrBadConn
 		}
@@ -38,7 +38,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
 		pktLen := int(uint32(data[0]) | uint32(data[1])<<8 | uint32(data[2])<<16)
 
 		if pktLen < 1 {
-			errLog.Print(errMalformPkt.Error())
+			errLog.Print(errMalformPkt)
 			mc.Close()
 			return nil, driver.ErrBadConn
 		}
@@ -56,7 +56,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
 		// Read packet body [pktLen bytes]
 		data, err = mc.buf.readNext(pktLen)
 		if err != nil {
-			errLog.Print(err.Error())
+			errLog.Print(err)
 			mc.Close()
 			return nil, driver.ErrBadConn
 		}
@@ -113,9 +113,9 @@ func (mc *mysqlConn) writePacket(data []byte) error {
 
 		// Handle error
 		if err == nil { // n != len(data)
-			errLog.Print(errMalformPkt.Error())
+			errLog.Print(errMalformPkt)
 		} else {
-			errLog.Print(err.Error())
+			errLog.Print(err)
 		}
 		return driver.ErrBadConn
 	}
@@ -228,7 +228,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
 	data := mc.buf.takeSmallBuffer(pktLen + 4)
 	if data == nil {
 		// can not take the buffer. Something must be wrong with the connection
-		errLog.Print(errBusyBuffer.Error())
+		errLog.Print(errBusyBuffer)
 		return driver.ErrBadConn
 	}
 
@@ -299,7 +299,7 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error {
 	data := mc.buf.takeSmallBuffer(pktLen + 4)
 	if data == nil {
 		// can not take the buffer. Something must be wrong with the connection
-		errLog.Print(errBusyBuffer.Error())
+		errLog.Print(errBusyBuffer)
 		return driver.ErrBadConn
 	}
 
@@ -320,7 +320,7 @@ func (mc *mysqlConn) writeCommandPacket(command byte) error {
 	data := mc.buf.takeSmallBuffer(4 + 1)
 	if data == nil {
 		// can not take the buffer. Something must be wrong with the connection
-		errLog.Print(errBusyBuffer.Error())
+		errLog.Print(errBusyBuffer)
 		return driver.ErrBadConn
 	}
 
@@ -339,7 +339,7 @@ func (mc *mysqlConn) writeCommandPacketStr(command byte, arg string) error {
 	data := mc.buf.takeBuffer(pktLen + 4)
 	if data == nil {
 		// can not take the buffer. Something must be wrong with the connection
-		errLog.Print(errBusyBuffer.Error())
+		errLog.Print(errBusyBuffer)
 		return driver.ErrBadConn
 	}
 
@@ -360,7 +360,7 @@ func (mc *mysqlConn) writeCommandPacketUint32(command byte, arg uint32) error {
 	data := mc.buf.takeSmallBuffer(4 + 1 + 4)
 	if data == nil {
 		// can not take the buffer. Something must be wrong with the connection
-		errLog.Print(errBusyBuffer.Error())
+		errLog.Print(errBusyBuffer)
 		return driver.ErrBadConn
 	}
 
@@ -751,7 +751,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
 	}
 	if data == nil {
 		// can not take the buffer. Something must be wrong with the connection
-		errLog.Print(errBusyBuffer.Error())
+		errLog.Print(errBusyBuffer)
 		return driver.ErrBadConn
 	}