Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
24246181
authored
2013-08-28 15:48:43 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
delete default console & add bench test
1 parent
b96f7e2e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
3 deletions
logs/console_test.go
logs/file_test.go
logs/log.go
logs/smtp.go
logs/smtp_test.go
logs/console_test.go
View file @
2424618
...
...
@@ -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 @
2424618
...
...
@@ -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 @
2424618
...
...
@@ -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 @
2424618
...
...
@@ -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 @
2424618
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment