提交 315d2746 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

parse pytest allure results

上级 f9fb7716
......@@ -234,4 +234,4 @@ upload_to:
@echo 'upload...'
@find ${QINIU_DIR} -name ".DS_Store" -type f -delete
@qshell qupload2 --src-dir=${QINIU_DIR} --bucket=download --thread-count=10 --log-file=qshell.log \
--skip-path-prefixes=zz,zd,zmanager,driver --rescan-local --overwrite --check-hash
--skip-path-prefixes=zv,zd,zmanager,driver --rescan-local --overwrite --check-hash
......@@ -2,6 +2,7 @@ package main
import (
"flag"
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
websocketHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
"github.com/easysoft/zentaoatf/internal/server/core/web"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
......@@ -37,6 +38,8 @@ func main() {
logUtils.PrintVersion(AppVersion, BuildTime, GoVersion, GitHash)
return
default:
commConsts.ExecFrom = commConsts.FromClient
webServer := web.Init(port)
if webServer == nil {
return
......
......@@ -53,6 +53,7 @@ require (
go.uber.org/zap v1.21.0 // indirect
golang.org/x/text v0.3.7
gopkg.in/ini.v1 v1.63.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gorm.io/driver/sqlite v1.2.6
gorm.io/gorm v1.22.3
gorm.io/plugin/dbresolver v1.1.0
......
......@@ -14,7 +14,6 @@ const (
ConfigDir = "conf"
ConfigFile = "ztf.conf"
LogDirName = "log"
LogBakDirName = "log-bak"
ExtNameSuite = "cs"
LogText = "log.txt"
ResultText = "result.txt"
......
package commConsts
import (
"github.com/awesome-gocui/gocui"
)
var (
LanguageZh = "zh"
LanguageEn = "en"
......@@ -23,8 +19,6 @@ var (
)
var (
Cui *gocui.Gui
MainViewHeight int
ConfigPath string
ServerWorkDir string
ServerWorkspaceDir string
......
......@@ -5,6 +5,7 @@ import (
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
commonUtils "github.com/easysoft/zentaoatf/pkg/lib/common"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
"gopkg.in/natefinch/lumberjack.v2"
"log"
"net/url"
"os"
......@@ -27,38 +28,39 @@ func InitLog() {
zapConfig := getLogConfig()
// print to console
// print to console and info、err files
var err error
zapConfig.EncoderConfig.EncodeLevel = nil
zapConfig.DisableCaller = true
zapConfig.EncoderConfig.TimeKey = ""
logUtils.LoggerStandard, err = zapConfig.Build()
logUtils.LoggerStandard, err = zapConfig.Build(zap.WrapCore(zapCore))
if err != nil {
log.Println("init console logger fail " + err.Error())
}
// print to console without detail
// print to console and info、err files without stacktrace detail
// by set DisableStacktrace to true
zapConfig.DisableStacktrace = true
logUtils.LoggerExecConsole, err = zapConfig.Build()
logUtils.LoggerExecConsole, err = zapConfig.Build(zap.WrapCore(zapCore))
if err != nil {
log.Println("init exec console logger fail " + err.Error())
}
}
// 执行日志,用于具体的测试执行
// write exec results by using zap log
func InitExecLog(workspacePath string) {
commConsts.ExecLogDir = logUtils.GetLogDir(workspacePath)
config := getLogConfig()
config.EncoderConfig.EncodeLevel = nil
// print to test log file
logPath := filepath.Join(commConsts.ExecLogDir, commConsts.LogText)
logPathInfo := filepath.Join(commConsts.ExecLogDir, commConsts.LogText)
if commonUtils.IsWin() {
logPath = filepath.Join(WinFileSchema, logPath)
logPathInfo = filepath.Join(WinFileSchema, logPathInfo)
zap.RegisterSink("winfile", newWinFileSink)
}
config.OutputPaths = []string{logPath}
config.OutputPaths = []string{logPathInfo}
var err error
logUtils.LoggerExecFile, err = config.Build()
......@@ -128,19 +130,12 @@ func getLogConfig() (config zap.Config) {
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
//EncodeLevel: zapcore.LowercaseLevelEncoder, // 小写编码器
EncodeTime: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.000"),
EncodeLevel: zapcore.CapitalColorLevelEncoder, //这里可以指定颜色
EncodeTime: zapcore.ISO8601TimeEncoder, // ISO8601 UTC 时间格式
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.FullCallerEncoder, // 全路径编码器
}
logPathInfo := filepath.Join(CONFIG.Zap.Director, "info.log")
logPathErr := filepath.Join(CONFIG.Zap.Director, "err.log")
if commonUtils.IsWin() {
logPathInfo = filepath.Join(WinFileSchema, logPathInfo)
logPathErr = filepath.Join(WinFileSchema, logPathErr)
}
config = zap.Config{
Level: zap.NewAtomicLevelAt(level), // 日志级别
Development: true, // 开发模式,堆栈跟踪
......@@ -149,11 +144,18 @@ func getLogConfig() (config zap.Config) {
//InitialFields: map[string]interface{}{"test_machine": "pc1"}, // 初始化字段
}
config.EncoderConfig.EncodeLevel = zapcore.LowercaseColorLevelEncoder //这里可以指定颜色
if commonUtils.IsWin() {
zap.RegisterSink("winfile", newWinFileSink)
}
config.OutputPaths = []string{"stdout", logPathInfo}
config.ErrorOutputPaths = []string{"stderr", logPathErr}
//if commonUtils.IsWin() {
// zap.RegisterSink("winfile", newWinFileSink)
//}
//
//logPathInfo := filepath.Join(CONFIG.Zap.Director, "info.log")
//logPathErr := filepath.Join(CONFIG.Zap.Director, "err.log")
//if commonUtils.IsWin() {
// logPathInfo = filepath.Join(WinFileSchema, logPathInfo)
// logPathErr = filepath.Join(WinFileSchema, logPathErr)
//}
//config.OutputPaths = []string{"stdout", logPathInfo}
//config.ErrorOutputPaths = []string{"stderr", logPathErr}
return
}
......@@ -170,3 +172,24 @@ func newWinFileSink(u *url.URL) (zap.Sink, error) {
}
return os.OpenFile(name, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
}
func zapCore(c zapcore.Core) zapcore.Core {
logPathInfo := filepath.Join(CONFIG.Zap.Director, "ztf.log")
w := zapcore.AddSync(&lumberjack.Logger{
Filename: logPathInfo,
LocalTime: true,
MaxSize: 300, // M
MaxAge: 30, // days
MaxBackups: 30,
})
core := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
w,
zap.DebugLevel,
)
cores := zapcore.NewTee(c, core)
return cores
}
......@@ -14,15 +14,15 @@ import (
)
func Get(url string) (ret []byte, err error) {
if commConsts.Verbose {
logUtils.Infof("===DEBUG=== request: %s", url)
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== request: %s", url)
}
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
}
return
......@@ -34,7 +34,7 @@ func Get(url string) (ret []byte, err error) {
resp, err := client.Do(req)
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
}
return
......@@ -42,7 +42,7 @@ func Get(url string) (ret []byte, err error) {
defer resp.Body.Close()
if !IsSuccessCode(resp.StatusCode) {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("read response failed, StatusCode: %d.", resp.StatusCode))
}
err = errors.New(resp.Status)
......@@ -50,12 +50,12 @@ func Get(url string) (ret []byte, err error) {
}
ret, err = ioutil.ReadAll(resp.Body)
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== response: %s", logUtils.ConvertUnicode(ret))
}
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("read response failed, error ", err.Error()))
}
return
......@@ -86,19 +86,19 @@ func Put(url string, data interface{}) (ret []byte, err error) {
}
func PostOrPut(url string, method string, data interface{}) (ret []byte, err error) {
if commConsts.Verbose {
logUtils.Infof("===DEBUG=== request: %s", url)
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== request: %s", url)
}
client := &http.Client{}
dataBytes, err := json.Marshal(data)
if commConsts.Verbose {
logUtils.Infof("===DEBUG=== data: %s", string(dataBytes))
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== data: %s", string(dataBytes))
}
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("marshal request failed, error: %s.", err.Error()))
}
return
......@@ -108,7 +108,7 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err
req, err := http.NewRequest(method, url, strings.NewReader(dataStr))
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error()))
}
return
......@@ -122,14 +122,14 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err
resp, err := client.Do(req)
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error()))
}
return
}
if !IsSuccessCode(resp.StatusCode) {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("post request return '%s'.", resp.Status))
}
err = errors.New(resp.Status)
......@@ -139,12 +139,12 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err
ret, err = ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== response: %s", logUtils.ConvertUnicode(ret))
}
if err != nil {
if commConsts.Verbose {
if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("read response failed, error: %s.", err.Error()))
}
return
......
......@@ -67,15 +67,6 @@ func ExecFilef(str string, args ...interface{}) {
func ExecResult(str string) {
LoggerExecResult.Info(str)
}
func ExecResultf(str string, args ...interface{}) {
msg := fmt.Sprintf(str, args...)
LoggerExecResult.Info(msg)
}
func PrintUnicode(str []byte) {
msg := ConvertUnicode(str)
LoggerStandard.Info(msg)
}
func ConvertUnicode(str []byte) string {
var a interface{}
......@@ -111,17 +102,6 @@ func GetWholeLine(msg string, char string) string {
return fmt.Sprintf("%s %s %s", preFixStr, msg, postFixStr)
}
func PrintToCmd(msg string, attr color.Attribute) {
output := color.Output
if attr == -1 {
fmt.Fprint(output, msg+"\n")
} else {
clr := color.New(attr)
clr.Fprint(output, msg+"\n")
}
}
func PrintVersion(appVersion, buildTime, goVersion, gitHash string) {
fmt.Printf("%s \n", appVersion)
fmt.Printf("Build TimeStamp: %s \n", buildTime)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册