From 2424618163c458ddf133ca192bf672445c58f5bd Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 28 Aug 2013 15:48:43 +0800 Subject: [PATCH] delete default console & add bench test --- logs/console_test.go | 9 +++++++++ logs/file_test.go | 9 +++++++++ logs/log.go | 2 +- logs/smtp.go | 6 +++++- logs/smtp_test.go | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/logs/console_test.go b/logs/console_test.go index 5ce0b1e1..f177e919 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -6,6 +6,7 @@ import ( func TestConsole(t *testing.T) { log := NewLogger(10000) + log.SetLogger("console", "") log.Trace("trace") log.Info("info") log.Warn("warning") @@ -19,3 +20,11 @@ func TestConsole(t *testing.T) { log.Debug("debug") log.Critical("critical") } + +func BenchmarkConsole(b *testing.B) { + log := NewLogger(10000) + log.SetLogger("console", "") + for i := 0; i < b.N; i++ { + log.Trace("trace") + } +} diff --git a/logs/file_test.go b/logs/file_test.go index c9b99eef..8f50276d 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -99,3 +99,12 @@ func exists(path string) (bool, error) { } return false, err } + +func BenchmarkFile(b *testing.B) { + log := NewLogger(100000) + log.SetLogger("file", `{"filename":"test4.log"}`) + for i := 0; i < b.N; i++ { + log.Trace("trace") + } + os.Remove("test4.log") +} diff --git a/logs/log.go b/logs/log.go index 8a9ac3c0..47fa906c 100644 --- a/logs/log.go +++ b/logs/log.go @@ -54,7 +54,7 @@ func NewLogger(channellen int64) *BeeLogger { bl := new(BeeLogger) bl.msg = make(chan *logMsg, channellen) bl.outputs = make(map[string]LoggerInterface) - bl.SetLogger("console", "") // default output to console + //bl.SetLogger("console", "") // default output to console go bl.StartLogger() return bl } diff --git a/logs/smtp.go b/logs/smtp.go index 19a03337..ecc33aa5 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -3,8 +3,10 @@ package logs import ( "encoding/json" "errors" + "fmt" "net/smtp" "strings" + "time" ) const ( @@ -77,7 +79,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { // and send the email all in one step. content_type := "Content-Type: text/plain" + "; charset=UTF-8" mailmsg := []byte("To: " + strings.Join(s.recipientAddresses, ";") + "\r\nFrom: " + s.username + "<" + s.username + - ">\r\nSubject: " + s.subject + "\r\n" + content_type + "\r\n\r\n" + msg) + ">\r\nSubject: " + s.subject + "\r\n" + content_type + "\r\n\r\n" + fmt.Sprintf(".%s", time.Now().Format("2006-01-02 15:04:05")) + msg) + err := smtp.SendMail( s.host, auth, @@ -85,6 +88,7 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { s.recipientAddresses, mailmsg, ) + return err } diff --git a/logs/smtp_test.go b/logs/smtp_test.go index c391c6ab..b01c5fb7 100644 --- a/logs/smtp_test.go +++ b/logs/smtp_test.go @@ -6,6 +6,6 @@ import ( func TestSmtp(t *testing.T) { log := NewLogger(10000) - log.SetLogger("smtp", `{"username":"xxxxxx@gmail.com","password":"xxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`) + log.SetLogger("smtp", `{"username":"beegotest@gmail.com","password":"xxxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`) log.Critical("sendmail critical") }