Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyibing committed Feb 23, 2021
1 parent 95bb1c3 commit 449e6ac
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# logger

1. [x] 包名: `github.com/fuyibing/log`.
1. [x] 版本: `v2`

> 本包在导入后, 扫描 `tmp/log.yaml``config/log.yaml` 并初始化,
> 详细配置参见本包的 `config/log.yaml` 注释.
### 通用用法.

```
log.Info("message.")
log.Infof("message %d: %s.", 1, "parse", "example")
```

### 带请求链

```
ctx := log.NewContext()
log.Debugfc(ctx, "debug fc")
log.Infofc(ctx, "info fc")
log.Warnfc(ctx, "warn fc")
log.Errorfc(ctx, "error fc")
```

### 在IRIS框架中

> 首先通过中间件, 在入口注册请求链.
```text
log.BindRequest(iris.Request())
```

> 在IRIS框架中使用.
```text
ctx := iris.Request().Context()
log.Debugfc(ctx, "debug fc")
log.Infofc(ctx, "info fc")
log.Warnfc(ctx, "warn fc")
log.Errorfc(ctx, "error fc")
```

### 自定义日志处理.

```text
log.Config.SetHandler(func(line interfaces.LineInterface) {
println("handler: ", line.SpanVersion(), line.Content())
})
ctx := log.NewContext()
log.Debugfc(ctx, "debug fc")
log.Infofc(ctx, "info fc")
log.Warnfc(ctx, "warn fc")
log.Errorfc(ctx, "error fc")
```

25 changes: 25 additions & 0 deletions tests/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// author: wsfuyibing <[email protected]>
// date: 2021-02-22

package tests

import (
"testing"

"github.com/fuyibing/log"
"github.com/fuyibing/log/interfaces"
)

func TestHandler(t *testing.T) {

log.Config.SetHandler(func(line interfaces.LineInterface) {
println("handler: ", line.SpanVersion(), line.Content())
})

ctx := log.NewContext()

log.Client.Debugfc(ctx, "debug fc")
log.Client.Infofc(ctx, "info fc")
log.Client.Warnfc(ctx, "warn fc")
log.Client.Errorfc(ctx, "error fc")
}

0 comments on commit 449e6ac

Please sign in to comment.