master
nikkiing 2 years ago
parent 51741f39ea
commit 057470df13
  1. 38
      README.md
  2. 36
      glog/es/logger.go
  3. 39
      glog/v1/README.md

@ -57,45 +57,7 @@ go get gitea.drugeyes.vip/pharnexbase/tools@v1.0.0
> 对称加密,目前包含:SHA1PRNG > 对称加密,目前包含:SHA1PRNG
### glog:全局日志
* v1
* 本地环境不变,dev,pre,pro 上传阿里
```go
// main.go 加入
func initLog() (log.Logger, func()) {
l, f := glog.NewLogger(&glog.LoggerConfig{
Env: "dev",
Id: id,
Name: Name,
Version: Version,
AliLogConfig: glog.AliLogConfig{
AccessKey: "",
AccessSecret: "",
Endpoint: "",
Project: "",
LogStore: "",
},
})
glog.NewHelper(l)
return l, f
}
// main函数加入
func main() {
...
logger, f := initLog()
defer f()
...
app, cleanup, err := wireApp(..., logger)
}
// 使用
glog.Glog.WithContext(ctx).Error("请输入正确手机号")
```

@ -0,0 +1,36 @@
package es
import (
"context"
"fmt"
"gitea.drugeyes.vip/pharnexbase/utils/glog/v1"
"strings"
)
type Logger struct {
}
// 这里es打印日志时需要实现的方法
func (l *Logger) Printf(format string, v ...interface{}) {
return
}
// 如果实现了此方法则不会调用上面的Printf
func (l *Logger) PrintfWithContext(ctx context.Context, format string, v ...interface{}) {
go func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("PrintfWithContext recover", r)
}
}()
for _, item := range v {
switch itemData := item.(type) {
case string:
itemData = strings.Replace(itemData, "\r\n", "", -1)
glog.Glog.WithContext(ctx).Info(itemData)
default:
glog.Glog.WithContext(ctx).Infof(format, itemData)
}
}
}()
}

@ -0,0 +1,39 @@
### glog:全局日志
* v1
* 本地环境不变,dev,pre,pro 上传阿里
```go
// main.go 加入
func initLog() (log.Logger, func()) {
l, f := glog.NewLogger(&glog.LoggerConfig{
Env: "dev",
Id: id,
Name: Name,
Version: Version,
AliLogConfig: glog.AliLogConfig{
AccessKey: "",
AccessSecret: "",
Endpoint: "",
Project: "",
LogStore: "",
},
})
glog.NewHelper(l)
return l, f
}
// main函数加入
func main() {
...
logger, f := initLog()
defer f()
...
app, cleanup, err := wireApp(..., logger)
}
// 使用
glog.Glog.WithContext(ctx).Error("请输入正确手机号")
```
Loading…
Cancel
Save