constellation/cli/internal/cmd/log.go

32 lines
526 B
Go
Raw Normal View History

/*
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"
"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)
}
func newCLILogger(cmd *cobra.Command) (debugLog, error) {
2024-02-08 09:20:01 -05:00
logLvl := slog.LevelInfo
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
}
2024-02-08 09:20:01 -05:00
return logger.NewTextLogger(logLvl), nil
}