Skip to content

Commit

Permalink
Suppress logrus exit status error message
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 committed Sep 25, 2024
1 parent 7542b4f commit abf9d86
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/cbuild/commands/build/buildcprj.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/cproject"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down
9 changes: 5 additions & 4 deletions cmd/cbuild/commands/build/buildcprj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"testing"

"github.com/Open-CMSIS-Pack/cbuild/v2/cmd/cbuild/commands"
log "github.com/sirupsen/logrus"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -49,21 +50,21 @@ func TestPreLogConfiguration(t *testing.T) {
cmd := commands.NewRootCmd()
cmd.SetArgs([]string{"buildcprj", cprjFile, "-C"})
_ = cmd.Execute()
assert.Equal(log.WarnLevel, log.GetLevel())
assert.Equal(logrus.WarnLevel, log.GetLevel())
})

t.Run("test quiet verbosity level", func(t *testing.T) {
cmd := commands.NewRootCmd()
cmd.SetArgs([]string{"buildcprj", cprjFile, "--quiet", "-C"})
_ = cmd.Execute()
assert.Equal(log.ErrorLevel, log.GetLevel())
assert.Equal(logrus.ErrorLevel, log.GetLevel())
})

t.Run("test debug debug level", func(t *testing.T) {
cmd := commands.NewRootCmd()
cmd.SetArgs([]string{"buildcprj", cprjFile, "--debug", "-C"})
_ = cmd.Execute()
assert.Equal(log.DebugLevel, log.GetLevel())
assert.Equal(logrus.DebugLevel, log.GetLevel())
})

t.Run("test path generation to log file", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cbuild/commands/list/list_contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/csolution"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/cbuild/commands/list/list_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/csolution"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/cbuild/commands/list/list_toolchains.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/csolution"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down
12 changes: 7 additions & 5 deletions cmd/cbuild/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/csolution"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"

log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -60,18 +62,18 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e

func preConfiguration(cmd *cobra.Command, args []string) error {
// configure log level
log.SetLevel(log.WarnLevel)
log.SetLevel(logrus.WarnLevel)
debug, _ := cmd.Flags().GetBool("debug")
quiet, _ := cmd.Flags().GetBool("quiet")
verbose, _ := cmd.Flags().GetBool("verbose")
logFile, _ := cmd.Flags().GetString("log")

if debug {
log.SetLevel(log.DebugLevel)
log.SetLevel(logrus.DebugLevel)
} else if verbose {
log.SetLevel(log.InfoLevel)
log.SetLevel(logrus.InfoLevel)
} else if quiet {
log.SetLevel(log.ErrorLevel)
log.SetLevel(logrus.ErrorLevel)
}

if logFile != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/cbuild/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/Open-CMSIS-Pack/cbuild/v2/cmd/cbuild/commands"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/inittest"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cbuild/commands/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/csolution"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down
15 changes: 7 additions & 8 deletions cmd/cbuild/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
package main

import (
"fmt"
"os"

"github.com/Open-CMSIS-Pack/cbuild/v2/cmd/cbuild/commands"
log "github.com/sirupsen/logrus"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
)

func main() {
log.SetFormatter(new(LogFormatter))
// log.SetFormatter(new(LogFormatter))
log.SetOutput(os.Stdout)

commands.Version = version
Expand All @@ -30,9 +29,9 @@ func main() {
}
}

type LogFormatter struct{}
// type LogFormatter struct{}

func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
msg := fmt.Sprintf("%s cbuild: %s\n", entry.Level.String(), entry.Message)
return []byte(msg), nil
}
// func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
// msg := fmt.Sprintf("%s cbuild: %s\n", entry.Level.String(), entry.Message)
// return []byte(msg), nil
// }
2 changes: 1 addition & 1 deletion pkg/builder/cbuildidx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

builder "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
utils "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
"github.com/hashicorp/go-version"
log "github.com/sirupsen/logrus"
)

const NinjaVersion = "1.11.1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/cproject/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

builder "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
utils "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
)

type CprjBuilder struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/csolution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/cbuildidx"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/builder/cproject"
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/errutils"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
utils "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
log "github.com/sirupsen/logrus"
)

type CSolutionBuilder struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"os/exec"

Check failure on line 11 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Vulnerability check

could not import os/exec (no metadata for os/exec)
"path/filepath"

Check failure on line 12 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Vulnerability check

could not import path/filepath (no metadata for path/filepath)

log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"

Check failure on line 14 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Build

no required module provides package github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger; to add it:

Check failure on line 14 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Test (linux)

no required module provides package github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger; to add it:

Check failure on line 14 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Test (linux)

no required module provides package github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger; to add it:

Check failure on line 14 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Vulnerability check

no required module provides package github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger; to add it:

Check failure on line 14 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Vulnerability check

could not import github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger (no metadata for github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger)

Check failure on line 14 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Test (darwin)

no required module provides package github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger; to add it:
"github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"

Check failure on line 15 in pkg/builder/interface.go

View workflow job for this annotation

GitHub Actions / Vulnerability check

could not import github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils (no metadata for github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils)
log "github.com/sirupsen/logrus"
)

type BuilderParams struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"bytes"
"os/exec"

log "github.com/sirupsen/logrus"
log "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/logger"
)

type RunnerInterface interface {
Expand Down

0 comments on commit abf9d86

Please sign in to comment.