From 449e6ac364f046c99d56eae53cfc83408545f7f7 Mon Sep 17 00:00:00 2001 From: fuyibing Date: Tue, 23 Feb 2021 13:54:29 +0800 Subject: [PATCH] no message --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/handler_test.go | 25 ++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 README.md create mode 100644 tests/handler_test.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..c3f4080 --- /dev/null +++ b/README.md @@ -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") +``` + diff --git a/tests/handler_test.go b/tests/handler_test.go new file mode 100644 index 0000000..b5ef29d --- /dev/null +++ b/tests/handler_test.go @@ -0,0 +1,25 @@ +// author: wsfuyibing +// 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") +}