fix: Skip flagd banner when non-console logger in use (#1516)
## This PR
- Moves the (very nice) flagd console banner behind a flag check to
avoid sending the (again, very nice) console banner to JSON log files,
sinks, k8s trailers, etc.
### How to test
```console
$ go run main.go start -f file:../config/samples/example_flags.flagd.json
______ __ ________ _______ ______
/_____/\ /_/\ /_______/\ /______/\ /_____/\
\::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
\:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
\:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
\:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
\_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
2025-01-15T19:41:51.347-0500 info cmd/start.go:124 flagd version: dev (HEAD), built at: unknown {"component": "start"}
2025-01-15T19:41:51.347-0500 info flag-sync/sync_service.go:87 starting flag sync service on port 8015 {"component": "FlagSyncService"}
2025-01-15T19:41:51.347-0500 info file/filepath_sync.go:62 Starting filepath sync notifier {"component": "sync", "sync": "fileinfo"}
2025-01-15T19:41:51.347-0500 info ofrep/ofrep_service.go:58 ofrep service listening at 8016 {"component": "OFREPService"}
2025-01-15T19:41:51.347-0500 info flag-evaluation/connect_service.go:249 metrics and probes listening at 8014 {"component": "service"}
2025-01-15T19:41:51.347-0500 info file/filepath_sync.go:101 watching filepath: ../config/samples/example_flags.flagd.json {"component": "sync", "sync": "fileinfo"}
2025-01-15T19:41:51.347-0500 info flag-evaluation/connect_service.go:229 Flag IResolver listening at [::]:8013 {"component": "service"}
```
```console
$ go run main.go start -f file:../config/samples/example_flags.flagd.json --log-format console
______ __ ________ _______ ______
/_____/\ /_/\ /_______/\ /______/\ /_____/\
\::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
\:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
\:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
\:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
\_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
2025-01-15T19:41:39.375-0500 info cmd/start.go:124 flagd version: dev (HEAD), built at: unknown {"component": "start"}
2025-01-15T19:41:39.376-0500 info flag-sync/sync_service.go:87 starting flag sync service on port 8015 {"component": "FlagSyncService"}
2025-01-15T19:41:39.378-0500 info file/filepath_sync.go:62 Starting filepath sync notifier {"component": "sync", "sync": "fileinfo"}
2025-01-15T19:41:39.380-0500 info ofrep/ofrep_service.go:58 ofrep service listening at 8016 {"component": "OFREPService"}
2025-01-15T19:41:39.380-0500 info flag-evaluation/connect_service.go:249 metrics and probes listening at 8014 {"component": "service"}
2025-01-15T19:41:39.380-0500 info flag-evaluation/connect_service.go:229 Flag IResolver listening at [::]:8013 {"component": "service"}
2025-01-15T19:41:39.381-0500 info file/filepath_sync.go:101 watching filepath: ../config/samples/example_flags.flagd.json {"component": "sync", "sync": "fileinfo"}
```
```console
$ go run main.go start -f file:../config/samples/example_flags.flagd.json --log-format json
{"level":"info","ts":"2025-01-15T19:41:19.857-0500","caller":"cmd/start.go:124","msg":"flagd version: dev (HEAD), built at: unknown","component":"start"}
{"level":"info","ts":"2025-01-15T19:41:19.857-0500","caller":"flag-sync/sync_service.go:87","msg":"starting flag sync service on port 8015","component":"FlagSyncService"}
{"level":"info","ts":"2025-01-15T19:41:19.861-0500","caller":"file/filepath_sync.go:62","msg":"Starting filepath sync notifier","component":"sync","sync":"fileinfo"}
{"level":"info","ts":"2025-01-15T19:41:19.863-0500","caller":"ofrep/ofrep_service.go:58","msg":"ofrep service listening at 8016","component":"OFREPService"}
{"level":"info","ts":"2025-01-15T19:41:19.863-0500","caller":"flag-evaluation/connect_service.go:249","msg":"metrics and probes listening at 8014","component":"service"}
{"level":"info","ts":"2025-01-15T19:41:19.864-0500","caller":"file/filepath_sync.go:101","msg":"watching filepath: ../config/samples/example_flags.flagd.json","component":"sync","sync":"fileinfo"}
{"level":"info","ts":"2025-01-15T19:41:19.864-0500","caller":"flag-evaluation/connect_service.go:229","msg":"Flag IResolver listening at [::]:8013","component":"service"}
```
Signed-off-by: Austin Drenski <austin@austindrenski.io>
Co-authored-by: Michael Beemer <beeme1mr@users.noreply.github.com>
This commit is contained in:
parent
600ce46d61
commit
bae9b6fb3b
|
|
@ -5,6 +5,8 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/dimiro1/banner"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -22,6 +24,21 @@ var rootCmd = &cobra.Command{
|
|||
Short: "flagd-proxy allows flagd to subscribe to CRD changes without the required permissions.",
|
||||
Long: ``,
|
||||
DisableAutoGenTag: true,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
if viper.GetString(logFormatFlagName) == "console" {
|
||||
banner.InitString(colorable.NewColorableStdout(), true, true, `
|
||||
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
|
||||
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
|
||||
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
|
||||
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
|
||||
{{ .AnsiColor.BrightRed }} Kubernetes Proxy
|
||||
{{ .AnsiColor.Default }}
|
||||
`)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
|
|
|
|||
|
|
@ -1,32 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/dimiro1/banner"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/open-feature/flagd/flagd-proxy/cmd"
|
||||
)
|
||||
import "github.com/open-feature/flagd/flagd-proxy/cmd"
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
commit = "HEAD"
|
||||
date = "unknown"
|
||||
bannerText = `
|
||||
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
|
||||
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
|
||||
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
|
||||
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
|
||||
{{ .AnsiColor.BrightRed }} Kubernetes Proxy
|
||||
{{ .AnsiColor.Default }}
|
||||
`
|
||||
)
|
||||
|
||||
func main() {
|
||||
banner.Init(colorable.NewColorableStdout(), true, true,
|
||||
bytes.NewBufferString(bannerText))
|
||||
cmd.Execute(version, commit, date)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/dimiro1/banner"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -23,6 +25,20 @@ var rootCmd = &cobra.Command{
|
|||
"It is designed to conform to Open Feature schema for flag definitions.",
|
||||
Long: ``,
|
||||
DisableAutoGenTag: true,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
if viper.GetString(logFormatFlagName) == "console" {
|
||||
banner.InitString(colorable.NewColorableStdout(), true, true, `
|
||||
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
|
||||
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
|
||||
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
|
||||
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
|
||||
{{ .AnsiColor.Default }}
|
||||
`)
|
||||
}
|
||||
},
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
|
|
|
|||
|
|
@ -1,31 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/dimiro1/banner"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/open-feature/flagd/flagd/cmd"
|
||||
)
|
||||
import "github.com/open-feature/flagd/flagd/cmd"
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
commit = "HEAD"
|
||||
date = "unknown"
|
||||
bannerText = `
|
||||
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
|
||||
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
|
||||
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
|
||||
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
|
||||
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
|
||||
{{ .AnsiColor.Default }}
|
||||
`
|
||||
)
|
||||
|
||||
func main() {
|
||||
banner.Init(colorable.NewColorableStdout(), true, true,
|
||||
bytes.NewBufferString(bannerText))
|
||||
cmd.Execute(version, commit, date)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue