Skip to content

Commit 58ec5b4

Browse files
committed
removed .Error() in logger, removed mutex to set logger
1 parent 12094b6 commit 58ec5b4

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

errors.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"io"
1616
"log"
1717
"os"
18-
"sync"
1918
)
2019

2120
var (
@@ -28,10 +27,8 @@ var (
2827
errPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?")
2928
errPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
3029
errBusyBuffer = errors.New("Busy buffer")
31-
errNoLogger = errors.New("logger is nil")
3230

33-
errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)
34-
errLogLock = &sync.Mutex{}
31+
errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)
3532
)
3633

3734
// Logger is used to log critical error messages.
@@ -43,11 +40,9 @@ type Logger interface {
4340
// The initial logger is stderr.
4441
func SetLogger(logger Logger) error {
4542
if logger == nil {
46-
return errNoLogger
43+
return errors.New("logger is nil")
4744
}
48-
errLogLock.Lock()
4945
errLog = logger
50-
errLogLock.Unlock()
5146
return nil
5247
}
5348

packets.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
2929
// Read packet header
3030
data, err := mc.buf.readNext(4)
3131
if err != nil {
32-
errLog.Print(err.Error())
32+
errLog.Print(err)
3333
mc.Close()
3434
return nil, driver.ErrBadConn
3535
}
@@ -38,7 +38,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
3838
pktLen := int(uint32(data[0]) | uint32(data[1])<<8 | uint32(data[2])<<16)
3939

4040
if pktLen < 1 {
41-
errLog.Print(errMalformPkt.Error())
41+
errLog.Print(errMalformPkt)
4242
mc.Close()
4343
return nil, driver.ErrBadConn
4444
}
@@ -56,7 +56,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
5656
// Read packet body [pktLen bytes]
5757
data, err = mc.buf.readNext(pktLen)
5858
if err != nil {
59-
errLog.Print(err.Error())
59+
errLog.Print(err)
6060
mc.Close()
6161
return nil, driver.ErrBadConn
6262
}
@@ -113,9 +113,9 @@ func (mc *mysqlConn) writePacket(data []byte) error {
113113

114114
// Handle error
115115
if err == nil { // n != len(data)
116-
errLog.Print(errMalformPkt.Error())
116+
errLog.Print(errMalformPkt)
117117
} else {
118-
errLog.Print(err.Error())
118+
errLog.Print(err)
119119
}
120120
return driver.ErrBadConn
121121
}
@@ -228,7 +228,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
228228
data := mc.buf.takeSmallBuffer(pktLen + 4)
229229
if data == nil {
230230
// can not take the buffer. Something must be wrong with the connection
231-
errLog.Print(errBusyBuffer.Error())
231+
errLog.Print(errBusyBuffer)
232232
return driver.ErrBadConn
233233
}
234234

@@ -299,7 +299,7 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error {
299299
data := mc.buf.takeSmallBuffer(pktLen + 4)
300300
if data == nil {
301301
// can not take the buffer. Something must be wrong with the connection
302-
errLog.Print(errBusyBuffer.Error())
302+
errLog.Print(errBusyBuffer)
303303
return driver.ErrBadConn
304304
}
305305

@@ -320,7 +320,7 @@ func (mc *mysqlConn) writeCommandPacket(command byte) error {
320320
data := mc.buf.takeSmallBuffer(4 + 1)
321321
if data == nil {
322322
// can not take the buffer. Something must be wrong with the connection
323-
errLog.Print(errBusyBuffer.Error())
323+
errLog.Print(errBusyBuffer)
324324
return driver.ErrBadConn
325325
}
326326

@@ -339,7 +339,7 @@ func (mc *mysqlConn) writeCommandPacketStr(command byte, arg string) error {
339339
data := mc.buf.takeBuffer(pktLen + 4)
340340
if data == nil {
341341
// can not take the buffer. Something must be wrong with the connection
342-
errLog.Print(errBusyBuffer.Error())
342+
errLog.Print(errBusyBuffer)
343343
return driver.ErrBadConn
344344
}
345345

@@ -360,7 +360,7 @@ func (mc *mysqlConn) writeCommandPacketUint32(command byte, arg uint32) error {
360360
data := mc.buf.takeSmallBuffer(4 + 1 + 4)
361361
if data == nil {
362362
// can not take the buffer. Something must be wrong with the connection
363-
errLog.Print(errBusyBuffer.Error())
363+
errLog.Print(errBusyBuffer)
364364
return driver.ErrBadConn
365365
}
366366

@@ -751,7 +751,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
751751
}
752752
if data == nil {
753753
// can not take the buffer. Something must be wrong with the connection
754-
errLog.Print(errBusyBuffer.Error())
754+
errLog.Print(errBusyBuffer)
755755
return driver.ErrBadConn
756756
}
757757

0 commit comments

Comments
 (0)