2014-01-03 10:26:29 +04:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStdStreamLog(t *testing.T) {
|
2014-04-06 18:09:23 +04:00
|
|
|
h, _ := NewStreamHandler(os.Stdout)
|
2014-01-03 10:26:29 +04:00
|
|
|
s := NewDefault(h)
|
|
|
|
s.Info("hello world")
|
|
|
|
|
|
|
|
s.Close()
|
|
|
|
|
|
|
|
Info("hello world")
|
|
|
|
}
|
2014-04-29 04:43:39 +04:00
|
|
|
|
|
|
|
func TestRotatingFileLog(t *testing.T) {
|
|
|
|
path := "./test_log"
|
|
|
|
os.RemoveAll(path)
|
|
|
|
|
|
|
|
os.Mkdir(path, 0777)
|
|
|
|
fileName := path + "/test"
|
|
|
|
|
|
|
|
h, err := NewRotatingFileHandler(fileName, 10, 2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, 10)
|
|
|
|
|
|
|
|
h.Write(buf)
|
|
|
|
|
|
|
|
h.Write(buf)
|
|
|
|
|
|
|
|
if _, err := os.Stat(fileName + ".1"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := os.Stat(fileName + ".2"); err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
h.Write(buf)
|
|
|
|
if _, err := os.Stat(fileName + ".2"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
h.Close()
|
|
|
|
|
|
|
|
os.RemoveAll(path)
|
|
|
|
}
|