24246181 by astaxie

delete default console & add bench test

1 parent b96f7e2e
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
6 6
7 func TestConsole(t *testing.T) { 7 func TestConsole(t *testing.T) {
8 log := NewLogger(10000) 8 log := NewLogger(10000)
9 log.SetLogger("console", "")
9 log.Trace("trace") 10 log.Trace("trace")
10 log.Info("info") 11 log.Info("info")
11 log.Warn("warning") 12 log.Warn("warning")
...@@ -19,3 +20,11 @@ func TestConsole(t *testing.T) { ...@@ -19,3 +20,11 @@ func TestConsole(t *testing.T) {
19 log.Debug("debug") 20 log.Debug("debug")
20 log.Critical("critical") 21 log.Critical("critical")
21 } 22 }
23
24 func BenchmarkConsole(b *testing.B) {
25 log := NewLogger(10000)
26 log.SetLogger("console", "")
27 for i := 0; i < b.N; i++ {
28 log.Trace("trace")
29 }
30 }
......
...@@ -99,3 +99,12 @@ func exists(path string) (bool, error) { ...@@ -99,3 +99,12 @@ func exists(path string) (bool, error) {
99 } 99 }
100 return false, err 100 return false, err
101 } 101 }
102
103 func BenchmarkFile(b *testing.B) {
104 log := NewLogger(100000)
105 log.SetLogger("file", `{"filename":"test4.log"}`)
106 for i := 0; i < b.N; i++ {
107 log.Trace("trace")
108 }
109 os.Remove("test4.log")
110 }
......
...@@ -54,7 +54,7 @@ func NewLogger(channellen int64) *BeeLogger { ...@@ -54,7 +54,7 @@ func NewLogger(channellen int64) *BeeLogger {
54 bl := new(BeeLogger) 54 bl := new(BeeLogger)
55 bl.msg = make(chan *logMsg, channellen) 55 bl.msg = make(chan *logMsg, channellen)
56 bl.outputs = make(map[string]LoggerInterface) 56 bl.outputs = make(map[string]LoggerInterface)
57 bl.SetLogger("console", "") // default output to console 57 //bl.SetLogger("console", "") // default output to console
58 go bl.StartLogger() 58 go bl.StartLogger()
59 return bl 59 return bl
60 } 60 }
......
...@@ -3,8 +3,10 @@ package logs ...@@ -3,8 +3,10 @@ package logs
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "errors" 5 "errors"
6 "fmt"
6 "net/smtp" 7 "net/smtp"
7 "strings" 8 "strings"
9 "time"
8 ) 10 )
9 11
10 const ( 12 const (
...@@ -77,7 +79,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { ...@@ -77,7 +79,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
77 // and send the email all in one step. 79 // and send the email all in one step.
78 content_type := "Content-Type: text/plain" + "; charset=UTF-8" 80 content_type := "Content-Type: text/plain" + "; charset=UTF-8"
79 mailmsg := []byte("To: " + strings.Join(s.recipientAddresses, ";") + "\r\nFrom: " + s.username + "<" + s.username + 81 mailmsg := []byte("To: " + strings.Join(s.recipientAddresses, ";") + "\r\nFrom: " + s.username + "<" + s.username +
80 ">\r\nSubject: " + s.subject + "\r\n" + content_type + "\r\n\r\n" + msg) 82 ">\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)
83
81 err := smtp.SendMail( 84 err := smtp.SendMail(
82 s.host, 85 s.host,
83 auth, 86 auth,
...@@ -85,6 +88,7 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { ...@@ -85,6 +88,7 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
85 s.recipientAddresses, 88 s.recipientAddresses,
86 mailmsg, 89 mailmsg,
87 ) 90 )
91
88 return err 92 return err
89 } 93 }
90 94
......
...@@ -6,6 +6,6 @@ import ( ...@@ -6,6 +6,6 @@ import (
6 6
7 func TestSmtp(t *testing.T) { 7 func TestSmtp(t *testing.T) {
8 log := NewLogger(10000) 8 log := NewLogger(10000)
9 log.SetLogger("smtp", `{"username":"xxxxxx@gmail.com","password":"xxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`) 9 log.SetLogger("smtp", `{"username":"beegotest@gmail.com","password":"xxxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`)
10 log.Critical("sendmail critical") 10 log.Critical("sendmail critical")
11 } 11 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!