mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:00:54 +00:00
test file modify
This commit is contained in:
parent
e1b73b33d0
commit
58730e3528
@ -23,7 +23,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFile(t *testing.T) {
|
func TestFile1(t *testing.T) {
|
||||||
log := NewLogger(10000)
|
log := NewLogger(10000)
|
||||||
log.SetLogger("file", `{"filename":"test.log"}`)
|
log.SetLogger("file", `{"filename":"test.log"}`)
|
||||||
log.Debug("debug")
|
log.Debug("debug")
|
||||||
@ -34,25 +34,24 @@ func TestFile(t *testing.T) {
|
|||||||
log.Alert("alert")
|
log.Alert("alert")
|
||||||
log.Critical("critical")
|
log.Critical("critical")
|
||||||
log.Emergency("emergency")
|
log.Emergency("emergency")
|
||||||
time.Sleep(time.Second * 4)
|
|
||||||
f, err := os.Open("test.log")
|
f, err := os.Open("test.log")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
b := bufio.NewReader(f)
|
b := bufio.NewReader(f)
|
||||||
linenum := 0
|
lineNum := 0
|
||||||
for {
|
for {
|
||||||
line, _, err := b.ReadLine()
|
line, _, err := b.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
linenum++
|
lineNum++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var expected = LevelDebug + 1
|
var expected = LevelDebug + 1
|
||||||
if linenum != expected {
|
if lineNum != expected {
|
||||||
t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines")
|
t.Fatal(lineNum, "not "+strconv.Itoa(expected)+" lines")
|
||||||
}
|
}
|
||||||
os.Remove("test.log")
|
os.Remove("test.log")
|
||||||
}
|
}
|
||||||
@ -68,25 +67,24 @@ func TestFile2(t *testing.T) {
|
|||||||
log.Alert("alert")
|
log.Alert("alert")
|
||||||
log.Critical("critical")
|
log.Critical("critical")
|
||||||
log.Emergency("emergency")
|
log.Emergency("emergency")
|
||||||
time.Sleep(time.Second * 4)
|
|
||||||
f, err := os.Open("test2.log")
|
f, err := os.Open("test2.log")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
b := bufio.NewReader(f)
|
b := bufio.NewReader(f)
|
||||||
linenum := 0
|
lineNum := 0
|
||||||
for {
|
for {
|
||||||
line, _, err := b.ReadLine()
|
line, _, err := b.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
linenum++
|
lineNum++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var expected = LevelError + 1
|
var expected = LevelError + 1
|
||||||
if linenum != expected {
|
if lineNum != expected {
|
||||||
t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines")
|
t.Fatal(lineNum, "not "+strconv.Itoa(expected)+" lines")
|
||||||
}
|
}
|
||||||
os.Remove("test2.log")
|
os.Remove("test2.log")
|
||||||
}
|
}
|
||||||
@ -102,13 +100,13 @@ func TestFileRotate(t *testing.T) {
|
|||||||
log.Alert("alert")
|
log.Alert("alert")
|
||||||
log.Critical("critical")
|
log.Critical("critical")
|
||||||
log.Emergency("emergency")
|
log.Emergency("emergency")
|
||||||
time.Sleep(time.Second * 4)
|
rotateName := "test3" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) + ".log"
|
||||||
rotatename := "test3" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) + ".log"
|
b, err := exists(rotateName)
|
||||||
b, err := exists(rotatename)
|
|
||||||
if !b || err != nil {
|
if !b || err != nil {
|
||||||
|
os.Remove("test3.log")
|
||||||
t.Fatal("rotate not generated")
|
t.Fatal("rotate not generated")
|
||||||
}
|
}
|
||||||
os.Remove(rotatename)
|
os.Remove(rotateName)
|
||||||
os.Remove("test3.log")
|
os.Remove("test3.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +130,8 @@ func BenchmarkFile(b *testing.B) {
|
|||||||
os.Remove("test4.log")
|
os.Remove("test4.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAsynchronousFile(b *testing.B) {
|
|
||||||
|
func BenchmarkFileAsynchronous(b *testing.B) {
|
||||||
log := NewLogger(100000)
|
log := NewLogger(100000)
|
||||||
log.SetLogger("file", `{"filename":"test4.log"}`)
|
log.SetLogger("file", `{"filename":"test4.log"}`)
|
||||||
log.Async()
|
log.Async()
|
||||||
@ -142,7 +141,7 @@ func BenchmarkAsynchronousFile(b *testing.B) {
|
|||||||
os.Remove("test4.log")
|
os.Remove("test4.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCallDepthFile(b *testing.B) {
|
func BenchmarkFileCallDepth(b *testing.B) {
|
||||||
log := NewLogger(100000)
|
log := NewLogger(100000)
|
||||||
log.SetLogger("file", `{"filename":"test4.log"}`)
|
log.SetLogger("file", `{"filename":"test4.log"}`)
|
||||||
log.EnableFuncCallDepth(true)
|
log.EnableFuncCallDepth(true)
|
||||||
@ -153,7 +152,7 @@ func BenchmarkCallDepthFile(b *testing.B) {
|
|||||||
os.Remove("test4.log")
|
os.Remove("test4.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAsynchronousCallDepthFile(b *testing.B) {
|
func BenchmarkFileAsynchronousCallDepth(b *testing.B) {
|
||||||
log := NewLogger(100000)
|
log := NewLogger(100000)
|
||||||
log.SetLogger("file", `{"filename":"test4.log"}`)
|
log.SetLogger("file", `{"filename":"test4.log"}`)
|
||||||
log.EnableFuncCallDepth(true)
|
log.EnableFuncCallDepth(true)
|
||||||
@ -164,3 +163,12 @@ func BenchmarkAsynchronousCallDepthFile(b *testing.B) {
|
|||||||
}
|
}
|
||||||
os.Remove("test4.log")
|
os.Remove("test4.log")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkFileOnGoroutine(b *testing.B) {
|
||||||
|
log := NewLogger(100000)
|
||||||
|
log.SetLogger("file", `{"filename":"test4.log"}`)
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
go log.Debug("debug")
|
||||||
|
}
|
||||||
|
os.Remove("test4.log")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user