diff --git a/pkg/cli/commands.go b/pkg/cli/commands.go index 75fbbc226..ddb047f9a 100644 --- a/pkg/cli/commands.go +++ b/pkg/cli/commands.go @@ -20,6 +20,7 @@ import ( "net/http" "chainguard.dev/apko/pkg/log" + "github.com/chainguard-dev/clog/gcp" charmlog "github.com/charmbracelet/log" "github.com/spf13/cobra" "sigs.k8s.io/release-utils/version" @@ -28,6 +29,7 @@ import ( func New() *cobra.Command { var logPolicy []string var level log.CharmLogLevel + var gcplog bool cmd := &cobra.Command{ Use: "melange", DisableAutoGenTag: true, @@ -36,17 +38,23 @@ func New() *cobra.Command { PersistentPreRunE: func(cmd *cobra.Command, args []string) error { http.DefaultTransport = userAgentTransport{http.DefaultTransport} - out, err := log.Writer(logPolicy) - if err != nil { - return fmt.Errorf("failed to create log writer: %w", err) + if gcplog { + slog.SetDefault(slog.New(gcp.NewHandler(slog.Level(level)))) + } else { + out, err := log.Writer(logPolicy) + if err != nil { + return fmt.Errorf("failed to create log writer: %w", err) + } + slog.SetDefault(slog.New(charmlog.NewWithOptions(out, charmlog.Options{ReportTimestamp: true, Level: charmlog.Level(level)}))) } - slog.SetDefault(slog.New(charmlog.NewWithOptions(out, charmlog.Options{ReportTimestamp: true, Level: charmlog.Level(level)}))) return nil }, } cmd.PersistentFlags().StringSliceVar(&logPolicy, "log-policy", []string{"builtin:stderr"}, "log policy (e.g. builtin:stderr, /tmp/log/foo)") cmd.PersistentFlags().Var(&level, "log-level", "log level (e.g. debug, info, warn, error)") + cmd.PersistentFlags().BoolVar(&gcplog, "gcplog", false, "use GCP logging") + _ = cmd.PersistentFlags().MarkHidden("gcplog") cmd.AddCommand(Build()) cmd.AddCommand(Bump())