Skip to content

Commit

Permalink
go-logger v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
donnie4w committed Jul 17, 2017
1 parent 88f430c commit 5a2f661
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions example/logger_test.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
package example

import (
"github.com/donnie4w/go-logger/logger"
"runtime"
"strconv"
"testing"
"time"

"github.com/donnie4w/go-logger/logger"
)

func log(i int) {
logger.Debug("Debug>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
logger.Info("Info>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
logger.Warn("Warn>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
logger.Error("Error>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
logger.Fatal("Fatal>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
func _log(i int) {
logger.Debug("Debug>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", strconv.Itoa(i))
// logger.Info("Info>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", strconv.Itoa(i))
// logger.Warn("Warn>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
// logger.Error("Error>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
// logger.Fatal("Fatal>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
}

func Test(t *testing.T) {
runtime.GOMAXPROCS(runtime.NumCPU())
//runtime.GOMAXPROCS(runtime.NumCPU())

//指定是否控制台打印,默认为true
logger.SetConsole(true)
// logger.SetConsole(true)
// logger.SetFormat("=====>%s##%s")
//指定日志文件备份方式为文件大小的方式
//第一个参数为日志文件存放目录
//第二个参数为日志文件命名
//第三个参数为备份文件最大数量
//第四个参数为备份文件大小
//第五个参数为文件大小的单位
//logger.SetRollingFile("d:/logtest", "test.log", 10, 5, logger.KB)
logger.SetRollingFile(`C:\Users\Thinkpad\Desktop\logtest`, "test.log", 10, 1, logger.KB)

//指定日志文件备份方式为日期的方式
//第一个参数为日志文件存放目录
//第二个参数为日志文件命名
logger.SetRollingDaily("d:/logtest", "test.log")
// logger.SetRollingDaily(`C:\Users\Thinkpad\Desktop\logtest`, "test.log")

//指定日志级别 ALL,DEBUG,INFO,WARN,ERROR,FATAL,OFF 级别由低到高
//一般习惯是测试阶段为debug,生成环境为info以上
logger.SetLevel(logger.ERROR)
//一般习惯是测试阶段为debug, 生成环境为info以上
logger.SetLevel(logger.DEBUG)

for i := 10000; i > 0; i-- {
go log(i)
time.Sleep(1000 * time.Millisecond)
for i := 100; i > 0; i-- {
go _log(i)
}
time.Sleep(15 * time.Second)
time.Sleep(2 * time.Second)
var lg = logger.GetLogger()

//重新指定log文件
lg.SetRollingFile(`C:\Users\Thinkpad\Desktop\logtest`, "test.log", 10, 1, logger.KB)
lg.SetLevelFile(logger.INFO, `C:\Users\Thinkpad\Desktop\logtest`, "info.log")
lg.SetLevelFile(logger.WARN, `C:\Users\Thinkpad\Desktop\logtest`, "warn.log")
lg.Debug("debug hello world")
for i := 100; i > 0; i-- {
go lg.Info("info hello world >>>>>>>>>>>>>>>>>> ", i)
}
lg.Warn("warn hello world")

time.Sleep(2 * time.Second)

}

0 comments on commit 5a2f661

Please sign in to comment.