Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
24246181
Commit
24246181
authored
Aug 28, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete default console & add bench test
parent
b96f7e2e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
3 deletions
+25
-3
console_test.go
logs/console_test.go
+9
-0
file_test.go
logs/file_test.go
+9
-0
log.go
logs/log.go
+1
-1
smtp.go
logs/smtp.go
+5
-1
smtp_test.go
logs/smtp_test.go
+1
-1
No files found.
logs/console_test.go
View file @
24246181
...
...
@@ -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"
)
}
}
logs/file_test.go
View file @
24246181
...
...
@@ -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"
)
}
logs/log.go
View file @
24246181
...
...
@@ -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
}
...
...
logs/smtp.go
View file @
24246181
...
...
@@ -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\n
From: "
+
s
.
username
+
"<"
+
s
.
username
+
">
\r\n
Subject: "
+
s
.
subject
+
"
\r\n
"
+
content_type
+
"
\r\n\r\n
"
+
msg
)
">
\r\n
Subject: "
+
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
}
...
...
logs/smtp_test.go
View file @
24246181
...
...
@@ -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":"x
xxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`
)
log
.
Critical
(
"sendmail critical"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment