mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: global set log with pretty console
This commit is contained in:
@@ -19,6 +19,10 @@ var boomCmd = &cobra.Command{
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
hrp.SetLogLevel(logLevel)
|
||||
if !logJSON {
|
||||
hrp.SetLogPretty()
|
||||
}
|
||||
|
||||
var paths []hrp.ITestCase
|
||||
for _, arg := range args {
|
||||
paths = append(paths, &hrp.TestCasePath{Path: arg})
|
||||
|
||||
@@ -16,6 +16,10 @@ var har2caseCmd = &cobra.Command{
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
hrp.SetLogLevel(logLevel)
|
||||
if !logJSON {
|
||||
hrp.SetLogPretty()
|
||||
}
|
||||
|
||||
var outputFiles []string
|
||||
for _, arg := range args {
|
||||
var outputPath string
|
||||
|
||||
@@ -17,6 +17,10 @@ var runCmd = &cobra.Command{
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
hrp.SetLogLevel(logLevel)
|
||||
if !logJSON {
|
||||
hrp.SetLogPretty()
|
||||
}
|
||||
|
||||
var paths []hrp.ITestCase
|
||||
for _, arg := range args {
|
||||
paths = append(paths, &hrp.TestCasePath{Path: arg})
|
||||
|
||||
9
log.go
9
log.go
@@ -10,10 +10,6 @@ import (
|
||||
|
||||
var log = zlog.Logger
|
||||
|
||||
func init() {
|
||||
log = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
}
|
||||
|
||||
func SetLogLevel(level string) {
|
||||
level = strings.ToUpper(level)
|
||||
log.Info().Msgf("Set log level to %s", level)
|
||||
@@ -33,6 +29,11 @@ func SetLogLevel(level string) {
|
||||
}
|
||||
}
|
||||
|
||||
func SetLogPretty() {
|
||||
log.Info().Msg("Set log to pretty console")
|
||||
log = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
}
|
||||
|
||||
func GetLogger() zerolog.Logger {
|
||||
return log
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user