Skip to content

Commit

Permalink
main: Initialise logger when exiting if needed (prometheus-community#…
Browse files Browse the repository at this point in the history
…1137)

Co-authored-by: Cristian Greco <[email protected]>
  • Loading branch information
iainlane and cristiangreco authored Sep 8, 2023
1 parent ed7af04 commit 824ace1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/yace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ var version = "custom-build"

var sem = semaphore.NewWeighted(1)

const (
defaultLogFormat = "json"
)

var (
addr string
configFile string
Expand All @@ -57,6 +61,10 @@ var (
func main() {
app := NewYACEApp()
if err := app.Run(os.Args); err != nil {
// if we exit very early we'll not have set up the logger yet
if logger == nil {
logger = logging.NewLogger(defaultLogFormat, debug, "version", version)
}
logger.Error(err, "Error running yace")
os.Exit(1)
}
Expand Down Expand Up @@ -97,7 +105,7 @@ func NewYACEApp() *cli.App {
},
&cli.StringFlag{
Name: "log.format",
Value: "json",
Value: defaultLogFormat,
Usage: "Output format of log messages. One of: [logfmt, json]. Default: [json].",
Destination: &logFormat,
Action: func(ctx *cli.Context, s string) error {
Expand Down

0 comments on commit 824ace1

Please sign in to comment.