1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 19:50:49 +00:00

delete default console & add bench test

This commit is contained in:
astaxie 2013-08-28 15:48:43 +08:00
parent b96f7e2ef2
commit 2424618163
5 changed files with 25 additions and 3 deletions

View File

@ -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")
}
}

View File

@ -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")
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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")
}