feat: global set log with pretty console

This commit is contained in:
debugtalk
2021-10-18 10:04:45 +08:00
parent 368ed9e14b
commit 268c4fd0af
4 changed files with 17 additions and 4 deletions

View File

@@ -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})

View File

@@ -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

View File

@@ -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
View File

@@ -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
}