mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-02 14:29:44 +08:00
feat: global set log level
This commit is contained in:
@@ -18,6 +18,7 @@ var boomCmd = &cobra.Command{
|
||||
$ hrp boom examples/ # run testcases in specified folder`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
hrp.SetLogLevel(logLevel)
|
||||
var paths []hrp.ITestCase
|
||||
for _, arg := range args {
|
||||
paths = append(paths, &hrp.TestCasePath{Path: arg})
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/hrp"
|
||||
"github.com/httprunner/hrp/har2case"
|
||||
)
|
||||
|
||||
@@ -14,6 +15,7 @@ var har2caseCmd = &cobra.Command{
|
||||
Long: `Convert HAR to json/yaml testcase files`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
hrp.SetLogLevel(logLevel)
|
||||
var outputFiles []string
|
||||
for _, arg := range args {
|
||||
var outputPath string
|
||||
|
||||
@@ -21,9 +21,17 @@ Copyright 2021 debugtalk`,
|
||||
Version: hrp.VERSION,
|
||||
}
|
||||
|
||||
var (
|
||||
logLevel string
|
||||
logJSON bool
|
||||
)
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
RootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||
RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
||||
|
||||
if err := RootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -16,6 +16,7 @@ var runCmd = &cobra.Command{
|
||||
$ hrp run examples/ # run testcases in specified folder`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
hrp.SetLogLevel(logLevel)
|
||||
var paths []hrp.ITestCase
|
||||
for _, arg := range args {
|
||||
paths = append(paths, &hrp.TestCasePath{Path: arg})
|
||||
|
||||
Reference in New Issue
Block a user