diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 05db6fe..d60deda 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,7 +22,7 @@ jobs: export PATH=$PATH:$(go env GOPATH)/bin go install github.com/securego/gosec/v2/cmd/gosec@latest gosec ./... - - name: go test -v ./... - run: go test -v ./... + - name: go test -race -v ./... + run: go test -race -v ./... - name: go build -v ./... run: go build -v ./... diff --git a/cmd/HellPot/HellPot.go b/cmd/HellPot/HellPot.go index 597d0d9..b2b3055 100644 --- a/cmd/HellPot/HellPot.go +++ b/cmd/HellPot/HellPot.go @@ -50,7 +50,7 @@ func main() { signal.Notify(stopChan, syscall.SIGINT, syscall.SIGTERM) go func() { - log.Error().Err(http.Serve()).Msg("HTTP error") + log.Fatal().Err(http.Serve()).Msg("HTTP error") }() <-stopChan // wait for SIGINT diff --git a/internal/config/logger.go b/internal/config/logger.go index a170e9e..2e9c55a 100644 --- a/internal/config/logger.go +++ b/internal/config/logger.go @@ -18,9 +18,7 @@ var ( logger zerolog.Logger ) -// StartLogger instantiates an instance of our zerolog loggger so we can hook it in our main package. -// While this does return a logger, it should not be used for additional retrievals of the logger. Use GetLogger() -func StartLogger(pretty bool, targets ...io.Writer) zerolog.Logger { +func prepLogDir() { logDir = snek.GetString("logger.directory") if !strings.HasSuffix(logDir, "/") { logDir += "/" @@ -29,7 +27,11 @@ func StartLogger(pretty bool, targets ...io.Writer) zerolog.Logger { println("cannot create log directory: " + logDir + "(" + err.Error() + ")") os.Exit(1) } +} +// StartLogger instantiates an instance of our zerolog loggger so we can hook it in our main package. +// While this does return a logger, it should not be used for additional retrievals of the logger. Use GetLogger(). +func StartLogger(pretty bool, targets ...io.Writer) zerolog.Logger { logFileName := "HellPot" if snek.GetBool("logger.use_date_filename") { @@ -44,9 +46,10 @@ func StartLogger(pretty bool, targets ...io.Writer) zerolog.Logger { case len(targets) > 0: logFile = io.MultiWriter(targets...) default: + prepLogDir() CurrentLogFile = path.Join(logDir, logFileName+".log") - - logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) // #nosec G304 G302 + //nolint:lll + logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) // #nosec G304 G302 -- we are not using user input to create the file if err != nil { println("cannot create log file: " + err.Error()) os.Exit(1) @@ -63,7 +66,7 @@ func StartLogger(pretty bool, targets ...io.Writer) zerolog.Logger { return logger } -// GetLogger retrieves our global logger object +// GetLogger retrieves our global logger object. func GetLogger() *zerolog.Logger { // future logic here return &logger