1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Merge pull request #530 from oxisto/slog

Added support for structured logging in `csaf_aggregator`
This commit is contained in:
Bernhard Herzog 2024-04-25 13:13:11 +02:00 committed by GitHub
commit 617deb4c17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 135 additions and 91 deletions

View file

@ -12,13 +12,14 @@ package options
import (
"fmt"
"log"
"log/slog"
"os"
"github.com/csaf-poc/csaf_distribution/v3/util"
"github.com/BurntSushi/toml"
"github.com/jessevdk/go-flags"
"github.com/mitchellh/go-homedir"
"github.com/csaf-poc/csaf_distribution/v3/util"
)
// Parser helps parsing command line arguments and loading
@ -147,3 +148,13 @@ func ErrorCheck(err error) {
log.Fatalf("error: %v\n", err)
}
}
// ErrorCheckStructured checks if err is not nil and terminates the program if
// so. This is similar to [ErrorCheck], but uses [slog] instead of the
// non-structured Go logging.
func ErrorCheckStructured(err error) {
if err != nil {
slog.Error("Error while executing program", "err", err)
os.Exit(1)
}
}