mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:30:56 +00:00
delete default console & add bench test
This commit is contained in:
parent
b96f7e2ef2
commit
2424618163
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
func TestConsole(t *testing.T) {
|
func TestConsole(t *testing.T) {
|
||||||
log := NewLogger(10000)
|
log := NewLogger(10000)
|
||||||
|
log.SetLogger("console", "")
|
||||||
log.Trace("trace")
|
log.Trace("trace")
|
||||||
log.Info("info")
|
log.Info("info")
|
||||||
log.Warn("warning")
|
log.Warn("warning")
|
||||||
@ -19,3 +20,11 @@ func TestConsole(t *testing.T) {
|
|||||||
log.Debug("debug")
|
log.Debug("debug")
|
||||||
log.Critical("critical")
|
log.Critical("critical")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkConsole(b *testing.B) {
|
||||||
|
log := NewLogger(10000)
|
||||||
|
log.SetLogger("console", "")
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
log.Trace("trace")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -99,3 +99,12 @@ func exists(path string) (bool, error) {
|
|||||||
}
|
}
|
||||||
return false, err
|
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")
|
||||||
|
}
|
||||||
|
@ -54,7 +54,7 @@ func NewLogger(channellen int64) *BeeLogger {
|
|||||||
bl := new(BeeLogger)
|
bl := new(BeeLogger)
|
||||||
bl.msg = make(chan *logMsg, channellen)
|
bl.msg = make(chan *logMsg, channellen)
|
||||||
bl.outputs = make(map[string]LoggerInterface)
|
bl.outputs = make(map[string]LoggerInterface)
|
||||||
bl.SetLogger("console", "") // default output to console
|
//bl.SetLogger("console", "") // default output to console
|
||||||
go bl.StartLogger()
|
go bl.StartLogger()
|
||||||
return bl
|
return bl
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package logs
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -77,7 +79,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
|
|||||||
// and send the email all in one step.
|
// and send the email all in one step.
|
||||||
content_type := "Content-Type: text/plain" + "; charset=UTF-8"
|
content_type := "Content-Type: text/plain" + "; charset=UTF-8"
|
||||||
mailmsg := []byte("To: " + strings.Join(s.recipientAddresses, ";") + "\r\nFrom: " + s.username + "<" + s.username +
|
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(
|
err := smtp.SendMail(
|
||||||
s.host,
|
s.host,
|
||||||
auth,
|
auth,
|
||||||
@ -85,6 +88,7 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
|
|||||||
s.recipientAddresses,
|
s.recipientAddresses,
|
||||||
mailmsg,
|
mailmsg,
|
||||||
)
|
)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,6 @@ import (
|
|||||||
|
|
||||||
func TestSmtp(t *testing.T) {
|
func TestSmtp(t *testing.T) {
|
||||||
log := NewLogger(10000)
|
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")
|
log.Critical("sendmail critical")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user