mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 21:39:41 +08:00
feat: replace log with logrus
This commit is contained in:
28
convert.go
28
convert.go
@@ -5,9 +5,9 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -24,14 +24,14 @@ func (tc *TestCase) ToTCase() (*TCase, error) {
|
||||
func (tc *TCase) Dump2JSON(path string) error {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Printf("convert absolute path error: %v, path: %v", err, path)
|
||||
log.Errorf("convert absolute path error: %v, path: %v", err, path)
|
||||
return err
|
||||
}
|
||||
log.Printf("dump testcase to json path: %s", path)
|
||||
log.Infof("dump testcase to json path: %s", path)
|
||||
file, _ := json.MarshalIndent(tc, "", " ")
|
||||
err = ioutil.WriteFile(path, file, 0644)
|
||||
if err != nil {
|
||||
log.Printf("dump json path error: %v", err)
|
||||
log.Errorf("dump json path error: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -40,10 +40,10 @@ func (tc *TCase) Dump2JSON(path string) error {
|
||||
func (tc *TCase) Dump2YAML(path string) error {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Printf("convert absolute path error: %v, path: %v", err, path)
|
||||
log.Errorf("convert absolute path error: %v, path: %v", err, path)
|
||||
return err
|
||||
}
|
||||
log.Printf("dump testcase to yaml path: %s", path)
|
||||
log.Infof("dump testcase to yaml path: %s", path)
|
||||
|
||||
// init yaml encoder
|
||||
buffer := new(bytes.Buffer)
|
||||
@@ -58,7 +58,7 @@ func (tc *TCase) Dump2YAML(path string) error {
|
||||
|
||||
err = ioutil.WriteFile(path, buffer.Bytes(), 0644)
|
||||
if err != nil {
|
||||
log.Printf("dump yaml path error: %v", err)
|
||||
log.Errorf("dump yaml path error: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -67,14 +67,14 @@ func (tc *TCase) Dump2YAML(path string) error {
|
||||
func loadFromJSON(path string) (*TCase, error) {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Printf("convert absolute path error: %v, path: %v", err, path)
|
||||
log.Errorf("convert absolute path error: %v, path: %v", err, path)
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("load testcase from json path: %s", path)
|
||||
log.Infof("load testcase from json path: %s", path)
|
||||
|
||||
file, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Printf("dump json path error: %v", err)
|
||||
log.Errorf("dump json path error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -88,14 +88,14 @@ func loadFromJSON(path string) (*TCase, error) {
|
||||
func loadFromYAML(path string) (*TCase, error) {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Printf("convert absolute path error: %v, path: %v", err, path)
|
||||
log.Errorf("convert absolute path error: %v, path: %v", err, path)
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("load testcase from yaml path: %s", path)
|
||||
log.Infof("load testcase from yaml path: %s", path)
|
||||
|
||||
file, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Printf("dump yaml path error: %v", err)
|
||||
log.Errorf("dump yaml path error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
|
||||
step: step,
|
||||
})
|
||||
} else {
|
||||
log.Printf("[convertTestCase] unexpected step: %+v", step)
|
||||
log.Warnf("[convertTestCase] unexpected step: %+v", step)
|
||||
}
|
||||
}
|
||||
return testCase, nil
|
||||
|
||||
Reference in New Issue
Block a user