提交 3e913407 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

update logs

上级 f6d020cb
......@@ -49,7 +49,7 @@ func CommitBug(ztfBug commDomain.ZtfBug, projectPath string) (err error) {
if err == nil {
msg = i118Utils.Sprintf("success_to_report_bug", ztfBug.Case)
} else {
msg = color.RedString(err.Error())
msg = color.RedString("commit bug failed, error: %s.", err.Error())
}
if commConsts.ComeFrom == "cmd" {
......
......@@ -35,7 +35,7 @@ func CommitResult(report commDomain.ZtfReport, productId, taskId string, project
if err == nil {
msg = color.GreenString(i118Utils.Sprintf("success_to_submit_test_result"))
} else {
msg = color.RedString(string(ret))
msg = color.RedString("commit result failed, error: %s.", err.Error())
err = errors.New(string(ret))
}
logUtils.Info(msg)
......
......@@ -32,12 +32,12 @@ func Download(url string, dst string) (err error) {
func HTTPDownload(uri string) ([]byte, error) {
res, err := http.Get(uri)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("download file failed, error: %s.", err.Error()))
}
defer res.Body.Close()
d, err := ioutil.ReadAll(res.Body)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("read downloaded file failed, error: %s.", err.Error()))
}
return d, err
}
......@@ -45,7 +45,7 @@ func HTTPDownload(uri string) ([]byte, error) {
func WriteDownloadFile(dst string, d []byte) error {
err := ioutil.WriteFile(dst, d, 0444)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("write download file failed, error: %s.", err.Error()))
}
return err
}
......@@ -29,17 +29,22 @@ func Get(url string) (ret []byte, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
return
}
resp, err := client.Do(req)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
logUtils.Infof(color.RedString("read response failed, error ", err.Error()))
return
}
bodyBytes, _ := ioutil.ReadAll(resp.Body)
if commConsts.Verbose {
logUtils.Infof(i118Utils.Sprintf("request_response"))
logUtils.Infof(logUtils.ConvertUnicode(bodyBytes))
......@@ -56,7 +61,7 @@ func Get(url string) (ret []byte, err error) {
return
} else {
if commConsts.Verbose {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("unmarshal response failed, error: %s.", err.Error()))
}
return
}
......@@ -87,7 +92,7 @@ func Post(url string, data interface{}, useFormFormat bool) (ret []byte, err err
dataBytes, err := json.Marshal(data)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("marshal request failed, error: %s.", err.Error()))
return
}
......@@ -106,7 +111,7 @@ func Post(url string, data interface{}, useFormFormat bool) (ret []byte, err err
req, err := http.NewRequest("POST", url, strings.NewReader(dataStr))
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error()))
return
}
......@@ -115,13 +120,13 @@ func Post(url string, data interface{}, useFormFormat bool) (ret []byte, err err
resp, err := client.Do(req)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error()))
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("read response failed, error: %s.", err.Error()))
return
}
......@@ -163,7 +168,7 @@ func PostStr(url string, params map[string]string) (ret []byte, err error) {
req, err := http.NewRequest("POST", url, strings.NewReader(paramStr))
if err != nil {
if commConsts.Verbose {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("post string failed, error: %s.", err.Error()))
}
return
}
......@@ -174,12 +179,17 @@ func PostStr(url string, params map[string]string) (ret []byte, err error) {
resp, err := client.Do(req)
if err != nil {
if commConsts.Verbose {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("post string failed, error: %s.", err.Error()))
}
return
}
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
logUtils.Infof(color.RedString("read response failed, error ", err.Error()))
return
}
if commConsts.Verbose {
logUtils.Infof(i118Utils.Sprintf("request_response"))
logUtils.Infof(logUtils.ConvertUnicode(bodyBytes))
......@@ -244,7 +254,7 @@ func GetRespErr(bytes []byte, url string) (ret []byte, err error) {
var zentaoResp serverDomain.ZentaoResp
err = json.Unmarshal(bytes, &zentaoResp)
if err != nil {
err = errors.New("Wrong Zentao response, unmarshal to serverDomain.ZentaoResp failed: " + err.Error())
err = errors.New("Wrong Zentao response, unmarshal to serverDomain.ZentaoResp failed, error " + err.Error())
if commConsts.Verbose {
if strings.Index(url, "login") < 0 { // jsonErr caused by login request return a html
logUtils.Infof(color.RedString(err.Error()))
......
......@@ -39,7 +39,7 @@ func GetDB() *gorm.DB {
})
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("open db failed, error: %s.", err.Error()))
}
_ = db.Use(
......@@ -57,7 +57,7 @@ func GetDB() *gorm.DB {
model.Models...,
)
if err != nil {
logUtils.Infof(color.RedString(err.Error()))
logUtils.Infof(color.RedString("migrate models failed, error: %s.", err.Error()))
}
return db
......
......@@ -6,7 +6,6 @@ import (
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/model"
"github.com/fatih/color"
"go.uber.org/zap"
"gorm.io/gorm"
)
......@@ -24,7 +23,7 @@ func (r *ProjectRepo) FindById(id uint) (po model.Project, err error) {
Where("NOT deleted").
First(&po).Error
if err != nil {
logUtils.Errorf("find project by id error", zap.String("error:", err.Error()))
logUtils.Errorf(color.RedString("find project by id failed, error: %s.", err.Error()))
return
}
......@@ -39,7 +38,7 @@ func (r *ProjectRepo) Create(project model.Project) (id uint, err error) {
err = r.DB.Model(&model.Project{}).Create(&project).Error
if err != nil {
logUtils.Errorf("create project error", zap.String("error:", err.Error()))
logUtils.Errorf(color.RedString("create project failed, error: %s.", err.Error()))
return 0, err
}
......@@ -51,7 +50,7 @@ func (r *ProjectRepo) Create(project model.Project) (id uint, err error) {
func (r *ProjectRepo) Update(id uint, project model.Project) error {
err := r.DB.Model(&model.Project{}).Where("id = ?", id).Updates(&project).Error
if err != nil {
logUtils.Errorf("update project error", zap.String("error:", err.Error()))
logUtils.Errorf(color.RedString("update project failed, error: %s.", err.Error()))
return err
}
......@@ -63,7 +62,7 @@ func (r *ProjectRepo) DeleteByPath(pth string) (err error) {
Delete(&model.Project{}).
Error
if err != nil {
logUtils.Errorf(color.RedString("delete project error", err.Error()))
logUtils.Errorf(color.RedString("delete project failed, error: %s.", err.Error()))
return
}
......
......@@ -15,7 +15,6 @@ import (
"github.com/kataras/iris/v12"
"github.com/snowlyg/helper/dir"
"github.com/snowlyg/helper/str"
"go.uber.org/zap"
)
var (
......@@ -39,12 +38,12 @@ func (s *FileService) UploadFile(ctx iris.Context, fh *multipart.FileHeader) (ir
path := filepath.Join(dir.GetCurrentAbPath(), "static", "upload", "images")
err = dir.InsureDir(path)
if err != nil {
logUtils.Infof(color.RedString("文件上传失败 %s", err.Error()))
logUtils.Infof(color.RedString("file upload failed, error: %s.", err.Error()))
return nil, err
}
_, err = ctx.SaveFormFile(fh, filepath.Join(path, filename))
if err != nil {
logUtils.Infof(color.RedString("文件上传失败 %s", err.Error()))
logUtils.Infof(color.RedString("file upload failed, error: %s.", err.Error()))
return nil, err
}
......@@ -104,14 +103,13 @@ func (s *FileService) addDir(pth string, parent *serverDomain.TestAsset) (dirNod
func GetFileName(name string) (string, error) {
fns := strings.Split(strings.TrimLeft(name, "./"), ".")
if len(fns) != 2 {
logUtils.Infof(color.RedString("文件上传失败 %s", "文件名错误"))
logUtils.Infof(color.RedString("file upload failed, error: wrong file name %s.", name))
return "", ErrEmpty
}
ext := fns[1]
md5, err := dir.MD5(name)
if err != nil {
logUtils.Errorf("文件上传失败", zap.String("trings.Split", name))
logUtils.Errorf(color.RedString("file upload failed, error: %s.", name))
return "", err
}
return str.Join(md5, ".", ext), nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册