diff options
author | Markus Wolf <KnisterPeter@users.noreply.github.com> | 2022-03-14 16:33:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 16:33:11 +0100 |
commit | 14c98015c57bf577619101ac4770f90c6435470b (patch) | |
tree | 92c6950e827bdde905adb159d6ac4af0cd57c6e2 /cmd | |
parent | build(deps): bump golangci/golangci-lint-action from 2 to 3.1.0 (#1019) (diff) | |
download | forgejo-act-14c98015c57bf577619101ac4770f90c6435470b.tar.xz forgejo-act-14c98015c57bf577619101ac4770f90c6435470b.zip |
feat: add json logger output (#1026)
* feat: add json logger output
This will allow to format log output as json.
This is helpful in cases where act is not executed on a 'local' machine.
* refactor: use runner config
Using the runner config to configure logging is cleaner.
Co-authored-by: Casey Lee <cplee@nektos.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/input.go | 1 | ||||
-rw-r--r-- | cmd/root.go | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/cmd/input.go b/cmd/input.go index 4dea829..e7f48df 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -38,6 +38,7 @@ type Input struct { autoRemove bool artifactServerPath string artifactServerPort string + jsonLogger bool } func (i *Input) resolve(path string) string { diff --git a/cmd/root.go b/cmd/root.go index 655510a..1e96166 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -60,6 +60,7 @@ func Execute(ctx context.Context, version string) { rootCmd.PersistentFlags().BoolVarP(&input.noWorkflowRecurse, "no-recurse", "", false, "Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag") rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory") rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") + rootCmd.PersistentFlags().BoolVar(&input.jsonLogger, "json", false, "Output logs in json format") rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps") rootCmd.PersistentFlags().BoolVarP(&input.dryrun, "dryrun", "n", false, "dryrun mode") rootCmd.PersistentFlags().StringVarP(&input.secretfile, "secret-file", "", ".secrets", "file with list of secrets to read from (e.g. --secret-file .secrets)") @@ -156,6 +157,10 @@ func readEnvs(path string, envs map[string]string) bool { //nolint:gocyclo func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { + if input.jsonLogger { + log.SetFormatter(&log.JSONFormatter{}) + } + if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && input.containerArchitecture == "" { l := log.New() l.SetFormatter(&log.TextFormatter{ @@ -266,6 +271,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str Workdir: input.Workdir(), BindWorkdir: input.bindWorkdir, LogOutput: !input.noOutput, + JSONLogger: input.jsonLogger, Env: envs, Secrets: secrets, InsecureSecrets: input.insecureSecrets, |