Skip to content

Commit

Permalink
增加设置输出等级接口
Browse files Browse the repository at this point in the history
  • Loading branch information
alex cai committed Nov 6, 2016
1 parent 22278ed commit 7f894dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,30 @@ go get -u github.com/ibbd-dev/go-async-log
普通写入日志文件

```go
lf := asyncLog.NewLogFile("/tmp/test.log")
lf := asyncLog.NewLogFile("/tmp/test.log")

// 设置按天切割文件,如果默认则是按小时
lf.SetRotate(asyncLog.RotateDate)
// 设置按天切割文件,如果默认则是按小时
lf.SetRotate(asyncLog.RotateDate)

_ = lf.Write("lf: hello world")
_ = lf.Write("lf: hello world")

// 注意:因为是每秒写入一次,所以这里需要暂停一下
time.Sleep(time.Second * 2)
// 注意:因为是每秒写入一次,所以这里需要暂停一下
time.Sleep(time.Second * 2)

```

写入错误等级文件

```go
infoFile := asyncLog.NewLevelLog("/tmp/test-info.log", asyncLog.LevelInfo) // 只有Info级别或者以上级别的日志才会被记录
infoFile.Debug("hello world") // 该日志不会写入文件
infoFile.Info("hello world")
infoFile.Error("hello world")
infoFile := asyncLog.NewLevelLog("/tmp/test-info.log", asyncLog.LevelInfo) // 只有Info级别或者以上级别的日志才会被记录
infoFile.Debug("hello world") // 该日志不会写入文件
infoFile.Info("hello world")
infoFile.Error("hello world")

time.Sleep(time.Second * 2)
// 需要改变日志写入等级时,例如测试阶段
infoFile.SetLevel(asyncLog.LevelDebug)

time.Sleep(time.Second * 2)
```

## 性能数据
Expand Down
4 changes: 4 additions & 0 deletions level.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func NewLevelLog(filename string, logLevel Priority) *LogFile {
return lf
}

func (lf *LogFile) SetLevel(logLevel Priority) {
lf.level = logLevel
}

func (lf *LogFile) Debug(msg string) error {
return lf.writeLevelMsg(msg, LevelDebug)
}
Expand Down

0 comments on commit 7f894dc

Please sign in to comment.