Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
feat: add --logformat flag to configure log output format (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
shokada committed Jan 9, 2021
1 parent 559df7b commit c755f79
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"os"
"strings"

"github.com/argoproj-labs/argocd-notifications/controller"
"github.com/argoproj-labs/argocd-notifications/pkg/services"
Expand Down Expand Up @@ -34,6 +35,7 @@ func newControllerCommand() *cobra.Command {
namespace string
appLabelSelector string
logLevel string
logFormat string
metricsPort int
argocdRepoServer string
)
Expand Down Expand Up @@ -64,6 +66,17 @@ func newControllerCommand() *cobra.Command {
}
log.SetLevel(level)

switch strings.ToLower(logFormat) {
case "json":
log.SetFormatter(&log.JSONFormatter{})
case "text":
if os.Getenv("FORCE_LOG_COLORS") == "1" {
log.SetFormatter(&log.TextFormatter{ForceColors: true})
}
default:
return fmt.Errorf("Unknown log format '%s'", logFormat)
}

argocdService, err := argocd.NewArgoCDService(k8sClient, namespace, argocdRepoServer)
if err != nil {
return err
Expand Down Expand Up @@ -117,6 +130,7 @@ func newControllerCommand() *cobra.Command {
command.Flags().StringVar(&appLabelSelector, "app-label-selector", "", "App label selector.")
command.Flags().StringVar(&namespace, "namespace", "", "Namespace which controller handles. Current namespace if empty.")
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json")
command.Flags().IntVar(&metricsPort, "metrics-port", defaultMetricsPort, "Metrics port")
command.Flags().StringVar(&argocdRepoServer, "argocd-repo-server", "argocd-repo-server:8081", "Argo CD repo server address")
return &command
Expand Down

0 comments on commit c755f79

Please sign in to comment.