2022-11-21 11:02:33 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-02-08 09:20:01 -05:00
|
|
|
"log/slog"
|
|
|
|
|
2022-11-21 11:02:33 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type debugLog interface {
|
2024-02-08 09:20:01 -05:00
|
|
|
Debug(msg string, args ...any)
|
2022-11-21 11:02:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newCLILogger(cmd *cobra.Command) (debugLog, error) {
|
2024-02-08 09:20:01 -05:00
|
|
|
logLvl := slog.LevelInfo
|
2022-11-21 11:02:33 -05:00
|
|
|
debugLog, err := cmd.Flags().GetBool("debug")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if debugLog {
|
2024-02-08 09:20:01 -05:00
|
|
|
logLvl = slog.LevelDebug
|
2022-11-21 11:02:33 -05:00
|
|
|
}
|
|
|
|
|
2024-02-08 09:20:01 -05:00
|
|
|
return logger.NewTextLogger(logLvl), nil
|
2022-11-21 11:02:33 -05:00
|
|
|
}
|