Skip to content

Commit 7e8329f

Browse files
committed
feat: allow JSON logging
1 parent 9d11c79 commit 7e8329f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
RemoteTendermintRpc string
3333
BinaryPath string
3434
LogLevel string
35+
JsonOutput bool
3536

3637
GithubOrg string
3738
GithubRepo string
@@ -63,15 +64,11 @@ var rootCmd = &cobra.Command{
6364
Long: "Scrape the data on Tendermint node.",
6465
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
6566
if ConfigPath == "" {
66-
log.Info().Msg("Config file not provided")
6767
return nil
6868
}
6969

70-
log.Info().Msg("Config file provided")
71-
7270
viper.SetConfigFile(ConfigPath)
7371
if err := viper.ReadInConfig(); err != nil {
74-
log.Info().Err(err).Msg("Error reading config file")
7572
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
7673
return err
7774
}
@@ -100,6 +97,10 @@ func Execute(cmd *cobra.Command, args []string) {
10097

10198
zerolog.SetGlobalLevel(logLevel)
10299

100+
if JsonOutput {
101+
log = zerolog.New(os.Stdout).With().Timestamp().Logger()
102+
}
103+
103104
http.HandleFunc("/metrics", Handler)
104105

105106
log.Info().Str("address", ListenAddress).Msg("Listening")
@@ -409,6 +410,7 @@ func main() {
409410
rootCmd.PersistentFlags().StringVar(&GithubOrg, "github-org", "", "Github organization name")
410411
rootCmd.PersistentFlags().StringVar(&GithubRepo, "github-repo", "", "Github repository name")
411412
rootCmd.PersistentFlags().StringVar(&GithubToken, "github-token", "", "Github personal access token")
413+
rootCmd.PersistentFlags().BoolVar(&JsonOutput, "json", false, "Output logs as JSON")
412414

413415
if err := rootCmd.Execute(); err != nil {
414416
log.Fatal().Err(err).Msg("Could not start application")

0 commit comments

Comments
 (0)