chore(config): remove zerolog
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
b83f36674b
commit
9225a3a856
3 changed files with 38 additions and 67 deletions
18
cmd/config.go
Normal file
18
cmd/config.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/kelseyhightower/envconfig"
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Config provides the system configuration.
|
||||||
|
Config struct {
|
||||||
|
Debug bool `envconfig:"DRONE_DEBUG"`
|
||||||
|
Trace bool `envconfig:"DRONE_TRACE"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// fromEnviron returns the settings from the environment.
|
||||||
|
func fromEnviron() (Config, error) {
|
||||||
|
cfg := Config{}
|
||||||
|
err := envconfig.Process("", &cfg)
|
||||||
|
return cfg, err
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import "github.com/kelseyhightower/envconfig"
|
|
||||||
|
|
||||||
type (
|
|
||||||
// Config provides the system configuration.
|
|
||||||
Config struct {
|
|
||||||
Logging Logging
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type Logging struct {
|
|
||||||
Debug bool `envconfig:"APP_LOGS_DEBUG"`
|
|
||||||
Level string `envconfig:"APP_LOGS_LEVEL" default:"info"`
|
|
||||||
NoColor bool `envconfig:"APP_LOGS_COLOR"`
|
|
||||||
Pretty bool `envconfig:"APP_LOGS_PRETTY"`
|
|
||||||
Text bool `envconfig:"APP_LOGS_TEXT"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Environ returns the settings from the environment.
|
|
||||||
func Environ() (Config, error) {
|
|
||||||
cfg := Config{}
|
|
||||||
err := envconfig.Process("", &cfg)
|
|
||||||
return cfg, err
|
|
||||||
}
|
|
62
cmd/root.go
62
cmd/root.go
|
@ -5,9 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.com/gitea/act_runner/cmd/config"
|
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
|
@ -15,9 +12,7 @@ import (
|
||||||
"github.com/nektos/act/pkg/common"
|
"github.com/nektos/act/pkg/common"
|
||||||
"github.com/nektos/act/pkg/model"
|
"github.com/nektos/act/pkg/model"
|
||||||
"github.com/nektos/act/pkg/runner"
|
"github.com/nektos/act/pkg/runner"
|
||||||
"github.com/rs/zerolog"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,34 +62,19 @@ func (i *Input) newPlatforms() map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function cfgures the logging.
|
// initLogging setup the global logrus logger.
|
||||||
func initLogging(cfg config.Config) {
|
func initLogging(cfg Config) {
|
||||||
isTerm := isatty.IsTerminal(os.Stdout.Fd())
|
isTerm := isatty.IsTerminal(os.Stdout.Fd())
|
||||||
|
log.SetFormatter(&log.TextFormatter{
|
||||||
|
DisableColors: !isTerm,
|
||||||
|
FullTimestamp: true,
|
||||||
|
})
|
||||||
|
|
||||||
switch strings.ToLower(cfg.Logging.Level) {
|
if cfg.Debug {
|
||||||
case "panic":
|
log.SetLevel(log.DebugLevel)
|
||||||
zerolog.SetGlobalLevel(zerolog.PanicLevel)
|
|
||||||
case "fatal":
|
|
||||||
zerolog.SetGlobalLevel(zerolog.FatalLevel)
|
|
||||||
case "error":
|
|
||||||
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
|
||||||
case "warn":
|
|
||||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
|
||||||
case "info":
|
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
||||||
case "debug":
|
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
||||||
default:
|
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
||||||
}
|
}
|
||||||
|
if cfg.Trace {
|
||||||
if cfg.Logging.Pretty || isTerm {
|
log.SetLevel(log.TraceLevel)
|
||||||
log.Logger = log.Output(
|
|
||||||
zerolog.ConsoleWriter{
|
|
||||||
Out: os.Stderr,
|
|
||||||
NoColor: cfg.Logging.NoColor || !isTerm,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +107,9 @@ func Execute(ctx context.Context) {
|
||||||
rootCmd.PersistentFlags().StringVarP(&envfile, "env-file", "", ".env", "Read in a file of environment variables.")
|
rootCmd.PersistentFlags().StringVarP(&envfile, "env-file", "", ".env", "Read in a file of environment variables.")
|
||||||
|
|
||||||
_ = godotenv.Load(envfile)
|
_ = godotenv.Load(envfile)
|
||||||
cfg, err := config.Environ()
|
cfg, err := fromEnviron()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().
|
log.Fatal("invalid cfguration")
|
||||||
Err(err).
|
|
||||||
Msg("invalid cfguration")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initLogging(cfg)
|
initLogging(cfg)
|
||||||
|
@ -173,7 +151,7 @@ func runTask(ctx context.Context, input *Input, jobID string) error {
|
||||||
if len(events) > 0 {
|
if len(events) > 0 {
|
||||||
// set default event type to first event
|
// set default event type to first event
|
||||||
// this way user dont have to specify the event.
|
// this way user dont have to specify the event.
|
||||||
log.Debug().Msgf("Using detected workflow event: %s", events[0])
|
log.Debugf("Using detected workflow event: %s", events[0])
|
||||||
eventName = events[0]
|
eventName = events[0]
|
||||||
} else {
|
} else {
|
||||||
if plan := planner.PlanEvent("push"); plan != nil {
|
if plan := planner.PlanEvent("push"); plan != nil {
|
||||||
|
@ -184,10 +162,10 @@ func runTask(ctx context.Context, input *Input, jobID string) error {
|
||||||
// build the plan for this run
|
// build the plan for this run
|
||||||
var plan *model.Plan
|
var plan *model.Plan
|
||||||
if jobID != "" {
|
if jobID != "" {
|
||||||
log.Debug().Msgf("Planning job: %s", jobID)
|
log.Debugf("Planning job: %s", jobID)
|
||||||
plan = planner.PlanJob(jobID)
|
plan = planner.PlanJob(jobID)
|
||||||
} else {
|
} else {
|
||||||
log.Debug().Msgf("Planning event: %s", eventName)
|
log.Debugf("Planning event: %s", eventName)
|
||||||
plan = planner.PlanEvent(eventName)
|
plan = planner.PlanEvent(eventName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,14 +224,14 @@ func runTask(ctx context.Context, input *Input, jobID string) error {
|
||||||
|
|
||||||
type taskLogHook struct{}
|
type taskLogHook struct{}
|
||||||
|
|
||||||
func (h *taskLogHook) Levels() []logrus.Level {
|
func (h *taskLogHook) Levels() []log.Level {
|
||||||
return logrus.AllLevels
|
return log.AllLevels
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *taskLogHook) Fire(entry *logrus.Entry) error {
|
func (h *taskLogHook) Fire(entry *log.Entry) error {
|
||||||
if flag, ok := entry.Data["raw_output"]; ok {
|
if flag, ok := entry.Data["raw_output"]; ok {
|
||||||
if flagVal, ok := flag.(bool); flagVal && ok {
|
if flagVal, ok := flag.(bool); flagVal && ok {
|
||||||
log.Info().Msgf("task log: %s", entry.Message)
|
log.Infof("task log: %s", entry.Message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue