提交 7b69c908 authored 作者: gukai's avatar gukai

library 日志

上级 87bffb83
# library
## stbz/library
胜天半子内部调用库
## 地址
https://gitlab.jxhh.com/stbz/library
## 限制
golang版本 >= 1.14
## 使用方法
```php
use Stbz\Api\SupplyClient;
//appkey、appSecret 在开放平台获取 https://open.jxhh.com
$appKey = "your appkey";
$appSecret = "your appSecret";
try {
$supplyClient = new SupplyClient($appKey,$appSecret);
} catch (OssException $e) {
printf(__FUNCTION__ . "creating supplyClient instance: FAILED\n");
printf($e->getMessage() . "\n");
return null;
}
//获取商品列表
$param = ['page'=>1, 'limit'=>20, 'source'=>2];//请求参数
$method = 'get';//请求方法
$action = 'v2/Goods/Lists';//请求资源名
$response = $supplyClient->getApiResponse($method,$action,$param);
```
module gitlab.jxhh.com/stbz/library
go 1.16
require github.com/gogf/gf v1.16.6
package logs
import (
"fmt"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/glog"
)
type RequestLogReq struct {
Path string //存储路径
RequestURI string //请求URI
RequestID string //请求RequestID
Method string //请求方法
Params string //请求参数
Response string //响应参数
Err error //错误信息
ServerName string //请求服务名称
ResponseTime string //响应时间
}
//统一请求日志 20211208 gk
func RequestLog(req RequestLogReq){
Info(req.Path, "请求ID:【%v】 服务名称: 【%v】 请求路径:【%v】 请求方法: 【%v】 请求参数: 【%v】 响应参数: 【%v】 响应时间:【%v ms】error:【%v】",
req.RequestID, req.ServerName, req.RequestURI, req.Method, req.Params,req.Response, req.ResponseTime, req.Err.Error())
if req.Err != nil {
Error("%+v",gerror.Wrap(req.Err, extra))
}
}
//记录info日志 20211208 gk
func Info(path string,format string, v ...interface{}) {
newPath := g.Log().GetPath() + "/" + path
glog.Path(newPath).File( "info-{Ymd}.log").Println(fmt.Sprintf(format, v...))
}
//记录error日志 20211208 gk
func Error(format string, v ...interface{}) {
newPath := g.Log().GetPath() + "/error/"
glog.Path(newPath).File("{Ymd}.log").Println(fmt.Sprintf(format, v...))
}
//检查错误 20211208 gk
func CheckErr(err error, extra string) bool {
if err != nil {
Error("%+v",gerror.Wrap(err, extra))
return true
}
return false
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论