Skip to content

Commit

Permalink
增加日志级别;去掉一些请求日志输出。 (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: jack30724 <[email protected]>
  • Loading branch information
jack30724 and jack30724 authored May 11, 2024
1 parent b37c19f commit 5bb8942
Show file tree
Hide file tree
Showing 37 changed files with 92 additions and 113 deletions.
14 changes: 7 additions & 7 deletions biz/service/base/service_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (svc *BaseService) Enter(iService IService, reqObj interface{}) dto.BaseRsp
Message: err1.Error()}
}

logger.AppLogger().Debugf("BaseService Enter, lanInvokeReq:%+v", lanInvokeReq)
// logger.AppLogger().Debugf("BaseService Enter, lanInvokeReq:%+v", lanInvokeReq)
svc.EncryptedLanRequestBodyData = []byte(lanInvokeReq.Body)
}

Expand Down Expand Up @@ -142,7 +142,7 @@ func (svc *BaseService) Enter(iService IService, reqObj interface{}) dto.BaseRsp
bodyDataDec = svc.EncryptedLanRequestBodyData
}

logger.AppLogger().Debugf("BaseService Enter, bodyDataDec:%+v", string(bodyDataDec))
// logger.AppLogger().Debugf("BaseService Enter, bodyDataDec:%+v", string(bodyDataDec))
err := encoding.JsonDecode(bodyDataDec, reqObj)
if err != nil {
logger.AppLogger().Warnf("BaseService.Enter, JsonDecode err:%+v", err)
Expand All @@ -163,10 +163,10 @@ func (svc *BaseService) Enter(iService IService, reqObj interface{}) dto.BaseRsp

svc.Req = reqObj

logger.AppLogger().Debugf("svc.Req:%+v", svc.Req)
// logger.AppLogger().Debugf("svc.Req:%+v", svc.Req) // 可能包含隐私字段,暂时不输出请求。
if svc.Req != nil {
valueOfReq := reflect.ValueOf(svc.Req)
logger.AppLogger().Debugf("valueOfReq:%+v", valueOfReq)
// logger.AppLogger().Debugf("valueOfReq:%+v", valueOfReq)
reqExtraInfoValue := reflect.Indirect(valueOfReq).FieldByName("ReqExtraInfo")
logger.AppLogger().Debugf("reqExtraInfoValue:%+v", reqExtraInfoValue)
if reqExtraInfoValue.IsValid() { // 如果请求结构定义中没有 ReqExtraInfo 字段,则不会继续执行.
Expand All @@ -187,8 +187,8 @@ func (svc *BaseService) Enter(iService IService, reqObj interface{}) dto.BaseRsp
}
}

logger.AppLogger().Debugf("BaseService, req: %+v", reqObj)
logger.AccessLogger().Debugf("[BaseService.Enter] svc.RequestId:%v, svc.Req:%+v", svc.RequestId, svc.Req)
// logger.AppLogger().Debugf("BaseService, req: %+v", reqObj)
// logger.AccessLogger().Debugf("[BaseService.Enter] svc.RequestId:%v, svc.Req:%+v", svc.RequestId, svc.Req)
return iService.Process()
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func (svc *BaseService) Leave() dto.BaseRspStr {
rsp := dto.BaseRspStr{Code: dto.AgentCodeOkStr,
Message: "OK",
Results: svc.Rsp}
logger.AppLogger().Debugf("BaseService Enter, Rsp:%+v", svc.Rsp)
// logger.AppLogger().Debugf("BaseService Enter, Rsp:%+v", svc.Rsp)
return rsp
}
}
2 changes: 1 addition & 1 deletion biz/service/bind/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type InitService struct {
func (svc *InitService) Process() dto.BaseRspStr {
logger.AppLogger().Debugf("InitService Process")
req := svc.Req.(*bindinit.InitReq)
logger.AppLogger().Debugf("InitService Process, req:%+v", req)
// logger.AppLogger().Debugf("InitService Process, req:%+v", req)
if req != nil && len(req.ClientUuid) > 0 && len(req.ClientVersion) > 0 {
clientinfo.SetClientVersion(req.ClientUuid, req.ClientVersion)
}
Expand Down
6 changes: 3 additions & 3 deletions biz/service/bind/internet/service/config/get_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package config

import (
"agent/biz/service/pair"
"agent/biz/model/device"
"agent/biz/model/dto"
"agent/biz/model/dto/bind/internet/service/config"
"agent/biz/service/base"
"agent/biz/service/call"
"agent/biz/service/pair"
cfg "agent/config"
"agent/utils/logger"
"fmt"
Expand Down Expand Up @@ -48,7 +48,7 @@ func GetUserInfo() ([]*UserInfo, error) {
var results Rsp
url := cfg.Config.Account.Member.Url + "?userId=1"
err := call.CallServiceByGet(url, nil, nil, &results)
logger.AppLogger().Debugf("InternetServiceGetConfig Process, err:%v, url:%v, results:%+v", err, url, results)
// logger.AppLogger().Debugf("InternetServiceGetConfig Process, err:%v, url:%v, results:%+v", err, url, results)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +64,7 @@ func (svc *InternetServiceGetConfig) Process() dto.BaseRspStr {
return dto.BaseRspStr{Code: dto.AgentCodeBadReqStr, RequestId: svc.RequestId, Message: err.Error()}
}
req := svc.Req.(*config.GetConfigReq)
logger.AppLogger().Debugf("InternetServiceGetConfig Process, req:%v", req)
// logger.AppLogger().Debugf("InternetServiceGetConfig Process, req:%v", req)

userInfos, err := GetUserInfo()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion biz/service/bind/internet/service/config/post_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (svc *InternetServiceConfig) Process() dto.BaseRspStr {
}

req := svc.Req.(*config.ConfigReq)
logger.AppLogger().Debugf("InternetServiceConfig Process, req:%+v", req)
// logger.AppLogger().Debugf("InternetServiceConfig Process, req:%+v", req)
if device.GetConfig().EnableInternetAccess { // 之前处于开启状态, 准备关闭
if req.EnableInternetAccess {
return svc.BaseService.Process()
Expand Down
2 changes: 1 addition & 1 deletion biz/service/bind/password/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (svc *VerifyService) Process() dto.BaseRspStr {
}

req := svc.Req.(*password.VerifyReq)
logger.AppLogger().Debugf("RevokeService Process, req:%+v", req)
// logger.AppLogger().Debugf("RevokeService Process, req:%+v", req)

microServerRsp, err := doCheck(req.Password, req.ClientUuid)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion biz/service/bind/revoke/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (svc *RevokeService) Process() dto.BaseRspStr {
}

req := svc.Req.(*revoke.RevokeReq)
logger.AppLogger().Debugf("RevokeService Process, req:%+v", req)
// logger.AppLogger().Debugf("RevokeService Process, req:%+v", req)
microServerRsp, err := doRevoke(req.Password, req.ClientUuid)
if err != nil {
logger.AppLogger().Debugf("%v", err)
Expand Down
4 changes: 2 additions & 2 deletions biz/service/bind/space/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (svc *SpaceCreateService) Process() dto.BaseRspStr {
rsp := &create.CreateRsp{}

req := svc.Req.(*create.CreateReq)
logger.AppLogger().Debugf("SpaceCreateService Process, req:%+v", req)
// logger.AppLogger().Debugf("SpaceCreateService Process, req:%+v", req)
logger.AppLogger().Debugf("SpaceCreateService Process, pairedInfo:%+v", svc.PairedInfo)
logger.AppLogger().Debugf("SpaceCreateService, rebind:%+v", svc.PairedInfo.Rebind())

Expand Down Expand Up @@ -163,7 +163,7 @@ func (svc *SpaceCreateService) registerDevice(req *create.CreateReq) (*dto.BaseR
}

func (svc *SpaceCreateService) callGateway(req *create.CreateReq) (call.MicroServerRsp, error) {
logger.AppLogger().Debugf("callGateway, req:%+v ", req)
// logger.AppLogger().Debugf("callGateway, req:%+v ", req)

var microServerRsp call.MicroServerRsp

Expand Down
10 changes: 5 additions & 5 deletions biz/service/call/call_micro_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func CallServiceByPost(url string, headers map[string]string, req, rsp interface
}
httpReq, httpRsp, body, err1 := utilshttp.PostJsonWithHeaders(url, req, headers, rsp)
if err1 != nil {
logger.AppLogger().Warnf("Failed CallServiceByPost, err:%v, @@httpReq:%+v, @@httpRsp:%+v, @@body:%v", err1, httpReq, httpRsp, string(body))
// logger.AppLogger().Warnf("Failed CallServiceByPost, err:%v, @@httpReq:%+v, @@httpRsp:%+v, @@body:%v", err1, httpReq, httpRsp, string(body))
return err1
}
logger.AppLogger().Debugf("CallServiceByPost, req:%+v", req)
// logger.AppLogger().Debugf("CallServiceByPost, req:%+v", req)
logger.AppLogger().Debugf("CallServiceByPost, rsp:%+v", rsp)
logger.AppLogger().Infof("CallServiceByPost, httpReq:%+v", httpReq)
logger.AppLogger().Infof("CallServiceByPost, httpRsp:%+v", httpRsp)
Expand Down Expand Up @@ -87,7 +87,7 @@ func CallServiceByFormStr(method, url string, reqStr string, rsp interface{}) (*
payload := strings.NewReader(reqStr)
client := &http.Client{Timeout: time.Second * 20}

logger.AppLogger().Infof("CallServiceByForm, method:%+v, url:%+v, reqStr:%+v, payload:%+v", method, url, reqStr, payload)
// logger.AppLogger().Infof("CallServiceByForm, method:%+v, url:%+v, reqStr:%+v, payload:%+v", method, url, reqStr, payload)

req, err := http.NewRequest(method, url, payload)
if err != nil {
Expand All @@ -102,14 +102,14 @@ func CallServiceByFormStr(method, url string, reqStr string, rsp interface{}) (*
}
defer resp.Body.Close()

logger.AppLogger().Infof("CallServiceByForm, httpReq:%+v", req)
// logger.AppLogger().Infof("CallServiceByForm, httpReq:%+v", req)
logger.AppLogger().Infof("CallServiceByForm, httpRsp:%+v", resp)

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return resp, fmt.Errorf("ReadAll err:%+v", err)
}
// fmt.Println(string(body))

logger.AppLogger().Infof("CallServiceByForm, string(body):%+v", string(body))

err = json.Unmarshal(body, &rsp)
Expand Down
2 changes: 1 addition & 1 deletion biz/service/did/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewGetDocument() *GetDocument {

func (svc *GetDocument) Process() dto.BaseRspStr {
req := svc.Req.(*document.GetDocumentReq)
logger.AppLogger().Debugf("GetDocument Process, svc.RequestId:%v, req:%+v", svc.RequestId, req)
// logger.AppLogger().Debugf("GetDocument Process, svc.RequestId:%v, req:%+v", svc.RequestId, req)

didDocBytes, err := did.GetDocumentFromFile(nil, req.AOID, req.DID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion biz/service/did/document/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewUpdateDocumentPassword() *UpdateDocumentPassword {

func (svc *UpdateDocumentPassword) Process() dto.BaseRspStr {
req := svc.Req.(*password.UpdateDocumentPasswordReq)
logger.AppLogger().Debugf("UpdateDocumentPassword Process, svc.RequestId:%v, req:%+v", svc.RequestId, req)
// logger.AppLogger().Debugf("UpdateDocumentPassword Process, svc.RequestId:%v, req:%+v", svc.RequestId, req)
if req == nil {
err1 := fmt.Errorf("request is nil")
logger.AppLogger().Debugf(err1.Error())
Expand Down
4 changes: 2 additions & 2 deletions biz/service/encwrapper/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func Dec(params ...string) ([]string, error) {
return nil, err1
}
rt := make([]string, 0)
for i, v := range params {
for _, v := range params {
d, err := DecParam(v)
if err != nil {
return nil, err
}
logger.AppLogger().Debugf("dec, parm[%v]=%v", i, v)
// logger.AppLogger().Debugf("dec, parm[%v]=%v", i, v)
rt = append(rt, string(d))
}
return rt, nil
Expand Down
2 changes: 1 addition & 1 deletion biz/service/network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type PostNetworkConfigService struct {

func (svc *PostNetworkConfigService) Process() dto.BaseRspStr {
req := svc.Req.(*network.NetworkConfigReq)
logger.AppLogger().Debugf("PostNetworkConfigService, req:%+v", req)
// logger.AppLogger().Debugf("PostNetworkConfigService, req:%+v", req)
abilityModel := device_ability.GetAbilityModel()
if !abilityModel.InnerDiskSupport {
err := fmt.Errorf("unsupported function")
Expand Down
2 changes: 1 addition & 1 deletion biz/service/network/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (svc *NetworkIgnoreService) Process() dto.BaseRspStr {
}

req := svc.Req.(*network.NetworkIgnoreReq)
logger.AppLogger().Debugf("PostNetworkConfigService, req:%+v", req)
// logger.AppLogger().Debugf("PostNetworkConfigService, req:%+v", req)

succ, err := utilsnetwork.ForgetWifi(req.WIFIName)
if err != nil {
Expand Down
27 changes: 1 addition & 26 deletions biz/service/pair/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

func ServiceInitial(req *dtopair.PasswordInfo) (dto.BaseRspStr, error) {
logger.AppLogger().Debugf("ServiceInitial")
logger.AccessLogger().Debugf("[ServiceInitial], req:%+v", req)
// logger.AccessLogger().Debugf("[ServiceInitial], req:%+v", req)
err := encwrapper.Check()
if err != nil {
err1 := fmt.Errorf("check failed, err:%v", err)
Expand All @@ -44,38 +44,13 @@ func ServiceInitial(req *dtopair.PasswordInfo) (dto.BaseRspStr, error) {
Message: err1.Error()}, err1
}

logger.AppLogger().Debugf("ServiceInitial, req.Password:%v", req.Password)
rt, err := encwrapper.Dec(req.Password)
if err != nil {
logger.AppLogger().Warnf("dec, err:%+v", err)
return dto.BaseRspStr{Code: dto.AgentCodeBadReqStr,
Message: err.Error()}, nil
}
password := rt[0]
logger.AppLogger().Debugf("ServiceInitial, password:%v", password)
// password := ""

// pairing 里面启动了.
// // up一下容器
// go docker.PostEvent(docker.EventPairing)
// // 等容器启动完成
// dockerRet := -1
// for i := 0; i < 600; i++ {
// time.Sleep(time.Duration(2) * time.Second)
// dockerRet = docker.GetDockerStatus()
// if dockerRet == docker.ContainersStarted || dockerRet == docker.ContainersStartedFail {
// break
// }
// }
// logger.AppLogger().Debugf("ServiceInitial, dockerRet:%v", dockerRet)

// // 容器没启动成功
// if dockerRet != 1 {
// rsp := dto.BaseRspStr{Code: dto.AgentCodeServerErrorStr,
// RequestId: random.GenUUID(),
// Message: fmt.Sprintf("GetDockerStatus: %v", dockerRet)}
// return rsp, nil
// }

// 等待 account 的 initial 接口调用成功
var err1 error
Expand Down
2 changes: 0 additions & 2 deletions biz/service/pair/key_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (
)

func ServiceKeyExchange(req *dtopair.KeyExchangeReq) (dto.BaseRspStr, error) {
logger.AppLogger().Debugf("ServiceKeyExchange, req:%+v", req)
logger.AccessLogger().Debugf("[ServiceKeyExchange], req:%+v", req)

if !clientinfo.ClientExchangePubKeyExchanged() {
err1 := fmt.Errorf("no public key exchanged")
Expand Down
2 changes: 0 additions & 2 deletions biz/service/pair/pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import (

// app与盒子的配对和初始化v1
func ServicePairing(req *dtopair.PairingReq) (dto.BaseRspStr, error) {
logger.AppLogger().Debugf("ServicePairing, req:%+v", req)
logger.AccessLogger().Debugf("[ServicePairing], req:%+v", req)

err := encwrapper.Check()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions biz/service/pair/pub_key_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ import (
)

func ServicePubKeyExchange(req *dtopair.PubKeyExchangeReq) (dto.BaseRspStr, error) {
logger.AppLogger().Debugf("ServicePubKeyExchange, req:%+v", req)
logger.AppLogger().Debugf("ServicePubKeyExchange, len(req.ClientPubKey):%+v", len(req.ClientPubKey))
logger.AppLogger().Debugf("ServicePubKeyExchange, req.ClientPubKey:%+v", req.ClientPubKey)
logger.AppLogger().Debugf("ServicePubKeyExchange, req.SignedBtid:%+v", req.SignedBtid)
logger.AccessLogger().Debugf("[ServicePubKeyExchange], req:%+v", req)

clientinfo.SetClientExchangePubKey(req.ClientPubKey)
clientinfo.SetClientExchangePriKey(req.ClientPriKey)
Expand Down
8 changes: 3 additions & 5 deletions biz/service/pair/register_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func ServiceRegisterBox() error {
var rsp registryRspStruct

tryTotal := 3
var httpReq *http.Request
// var httpReq *http.Request
var httpRsp *http.Response
var body []byte
var err1 error
for i := 0; i < tryTotal; i++ {
httpReq, httpRsp, body, err1 = utilshttp.PostJsonWithHeaders(url, parms, headers, &rsp)
_, httpRsp, body, err1 = utilshttp.PostJsonWithHeaders(url, parms, headers, &rsp)
if err1 != nil {
logger.AppLogger().Warnf("Failed PostJson, err:%v, @@httpReq:%+v, @@httpRsp:%+v, @@body:%v", err1, httpReq, httpRsp, string(body))
// logger.AppLogger().Warnf("Failed PostJson, err:%v, @@httpReq:%+v, @@httpRsp:%+v, @@body:%v", err1, httpReq, httpRsp, string(body))
if i == tryTotal-1 {
return err1
}
Expand All @@ -96,9 +96,7 @@ func ServiceRegisterBox() error {

logger.AppLogger().Infof("ServiceRegisterBox, parms:%+v", parms)
logger.AppLogger().Infof("ServiceRegisterBox, rsp:%+v", rsp)
logger.AppLogger().Infof("ServiceRegisterBox, httpReq:%+v", httpReq)
logger.AppLogger().Infof("ServiceRegisterBox, httpRsp:%+v", httpRsp)
logger.AppLogger().Infof("ServiceRegisterBox, body:%v", string(body))

if httpRsp.StatusCode == http.StatusOK {
// 保存盒子信息
Expand Down
3 changes: 0 additions & 3 deletions biz/service/pair/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (

// 管理员解绑
func ServiceRevoke(req *dtopair.RevokeReq) (dto.BaseRspStr, error) {
logger.AppLogger().Debugf("ServiceRevoke, req:%+v", req)
logger.AccessLogger().Debugf("[ServiceRevoke], req:%+v", req)

err := encwrapper.Check()
if err != nil {
Expand Down Expand Up @@ -63,7 +61,6 @@ func ServiceRevoke(req *dtopair.RevokeReq) (dto.BaseRspStr, error) {
clientUUID = rt[0]
}

logger.AppLogger().Debugf("password:%+v, clientUUID=%v", password, clientUUID)
return doRevoke(password, clientUUID)
}

Expand Down
6 changes: 1 addition & 5 deletions biz/service/pair/setpassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ import (

func ServiceSetPassword(req *dtopair.PasswordInfo) (dto.BaseRspStr, error) {

logger.AppLogger().Debugf("ServiceSetPassword, req:%+v", req)
logger.AccessLogger().Debugf("[ServiceSetPassword], req:%+v", req)

err := encwrapper.Check()
if err != nil {
logger.AppLogger().Warnf("check, err:%+v", err)
Expand All @@ -46,13 +43,12 @@ func ServiceSetPassword(req *dtopair.PasswordInfo) (dto.BaseRspStr, error) {

rt, err := encwrapper.Dec(req.Password)
if err != nil {
logger.AppLogger().Warnf("dec, err:%+v", err)
// logger.AppLogger().Warnf("dec, err:%+v", err)
return dto.BaseRspStr{Code: dto.AgentCodeBadReqStr,
Message: err.Error()}, nil
}
password := rt[0]

logger.AppLogger().Debugf("password:%+v", password)
return doSetPassword(password)
}

Expand Down
Loading

0 comments on commit 5bb8942

Please sign in to comment.