Permalink
Browse files

Fix to separate write and send processing methods

  • Loading branch information...
daichirata committed Dec 15, 2017
1 parent b81248d commit 3112bd1ec8a12ed164560fa34bd5598b0caabcf1
Showing with 14 additions and 8 deletions.
  1. +14 −8 logger.go
View
@@ -111,36 +111,42 @@ func (logger *Logger) disconnect() error {
return err
}
const maxWriteAttempts = 3
const maxWriteAttempts = 2
func (logger *Logger) send() error {
messages := logger.buf.Remove()
func (logger *Logger) write(messages []*Message) error {
if len(messages) == 0 {
return nil
}
var data []byte
for _, m := range messages {
data = append(data, m.buf.Bytes()...)
}
var err error
for i := 0; i < maxWriteAttempts; i++ {
err = logger.connect()
if err == nil {
_, err := logger.conn.Write(data)
if err == nil {
for _, m := range messages {
putMessage(m)
}
break
}
}
logger.disconnect()
}
return err
}
func (logger *Logger) send() error {
messages := logger.buf.Remove()
err := logger.write(messages)
if err != nil {
logger.buf.Back(messages)
return err
}
return err
for _, m := range messages {
putMessage(m)
}
return nil
}
func (logger *Logger) start() {

0 comments on commit 3112bd1

Please sign in to comment.