Skip to content

Commit 1dc8c4c

Browse files
authoredMar 27, 2024··
initialize logging earlier in the main function (#1935)
1 parent 2432d4a commit 1dc8c4c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed
 

‎cmd/trivy-operator/main.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ var (
3232

3333
// main is the entrypoint of the Trivy Operator executable command.
3434
func main() {
35-
if err := run(); err != nil {
36-
fmt.Fprintf(os.Stderr, "unable to run trivy operator: %v\n", err)
37-
os.Exit(1)
38-
}
39-
}
40-
41-
func run() error {
35+
// Fetch operator configuration early.
4236
operatorConfig, err := etc.GetOperatorConfig()
4337
if err != nil {
44-
return fmt.Errorf("getting operator config: %w", err)
38+
fmt.Fprintf(os.Stderr, "error getting operator config: %v\n", err)
39+
os.Exit(1)
4540
}
4641

42+
// Initialize the logger based on the LogDevMode from the config.
4743
log.SetLogger(zap.New(zap.UseDevMode(operatorConfig.LogDevMode)))
4844

45+
if err := run(operatorConfig); err != nil {
46+
fmt.Fprintf(os.Stderr, "unable to run trivy operator: %v\n", err)
47+
os.Exit(1)
48+
}
49+
}
50+
51+
func run(operatorConfig etc.Config) error {
4952
setupLog.Info("Starting operator", "buildInfo", buildInfo)
5053

5154
return operator.Start(ctrl.SetupSignalHandler(), buildInfo, operatorConfig)

0 commit comments

Comments
 (0)
Please sign in to comment.