Skip to content

Commit

Permalink
fix: errors being logged in json format when they shouldn't
Browse files Browse the repository at this point in the history
before:

```
4:07PM DBG executing command cmd="/usr/local/go/bin/go mod why -m -vendor github.com/CycloneDX/cyclonedx-go" dir=/work
4:07PM DBG failed to initialize build cache at /.cache/go-build: mkdir /.cache: permission denied
{"level":"error","error":"failed to download modules: command `/usr/local/go/bin/go mod why -m -vendor github.com/CycloneDX/cyclonedx-go` failed: exit status 1","time":"2023-08-03T16:07:49Z"}
```

after:

```
4:05PM DBG executing command cmd="/usr/local/go/bin/go mod why -m -vendor github.com/CycloneDX/cyclonedx-go" dir=/work
4:05PM DBG failed to initialize build cache at /.cache/go-build: mkdir /.cache: permission denied
4:05PM ERR error="failed to download modules: command `/usr/local/go/bin/go mod why -m -vendor github.com/CycloneDX/cyclonedx-go` failed: exit status 1"
```

Signed-off-by: nscuro <nscuro@protonmail.com>
  • Loading branch information
nscuro committed Aug 3, 2023
1 parent c44a3b1 commit 38c50d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
8 changes: 7 additions & 1 deletion cmd/cyclonedx-gomod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main
import (
"context"
"fmt"
"github.com/rs/zerolog"
"os"

"github.com/rs/zerolog/log"
Expand All @@ -34,7 +35,12 @@ func main() {
if _, ok := err.(*options.ValidationError); ok {
_, _ = fmt.Fprintln(os.Stderr, err)
} else {
log.Err(err).Msg("")
logger := log.Output(zerolog.ConsoleWriter{
Out: os.Stderr,
NoColor: os.Getenv("CI") != "",
})

logger.Err(err).Msg("")
}
os.Exit(1)
}
Expand Down
14 changes: 0 additions & 14 deletions internal/cli/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@ type LogOptions struct {
Verbose bool
}

// ConfigureLogger configures the global logger according to LogOptions.
func (l LogOptions) ConfigureLogger() {
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: os.Stderr,
NoColor: os.Getenv("CI") != "",
})

if l.Verbose {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
}

// Logger returns a zerolog.Logger configured according to LogOptions.
func (l LogOptions) Logger() zerolog.Logger {
logger := log.Output(zerolog.ConsoleWriter{
Expand Down

0 comments on commit 38c50d8

Please sign in to comment.