Skip to content

Commit

Permalink
Merge pull request #298 from albertvaka/master
Browse files Browse the repository at this point in the history
Added --log-level argument
  • Loading branch information
sgotti committed Jul 9, 2017
2 parents cafe66d + e93f6fc commit 0f82e68
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
17 changes: 15 additions & 2 deletions cmd/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type config struct {
storeSkipTlsVerify bool
dataDir string
clusterName string
logLevel string
debug bool
pgListenAddress string
pgPort string
Expand Down Expand Up @@ -115,9 +116,11 @@ func init() {
cmdKeeper.PersistentFlags().StringVar(&cfg.pgSUUsername, "pg-su-username", user, "postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.")
cmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPassword, "pg-su-password", "", "postgres superuser password. Needed for pg_rewind based synchronization. If provided it'll be configured on db initialization. Only one of --pg-su-password or --pg-su-passwordfile is required. Must be the same for all keepers.")
cmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPasswordFile, "pg-su-passwordfile", "", "postgres superuser password file. Requires --pg-su-username. Must be the same for all keepers)")
cmdKeeper.PersistentFlags().StringVar(&cfg.logLevel, "log-level", "info", "debug, info (default), warn or error")
cmdKeeper.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging")

cmdKeeper.PersistentFlags().MarkDeprecated("id", "please use --uid")
cmdKeeper.PersistentFlags().MarkDeprecated("debug", "use --log-level=debug instead")
}

var mandatoryPGParameters = common.Parameters{
Expand Down Expand Up @@ -314,7 +317,6 @@ type PostgresKeeper struct {
storeEndpoints string
listenAddress string
port string
debug bool
pgListenAddress string
pgPort string
pgBinPath string
Expand Down Expand Up @@ -366,7 +368,6 @@ func NewPostgresKeeper(cfg *config, stop chan bool, end chan error) (*PostgresKe
storeBackend: cfg.storeBackend,
storeEndpoints: cfg.storeEndpoints,

debug: cfg.debug,
pgListenAddress: cfg.pgListenAddress,
pgPort: cfg.pgPort,
pgBinPath: cfg.pgBinPath,
Expand Down Expand Up @@ -1513,6 +1514,18 @@ func keeper(cmd *cobra.Command, args []string) {
if cfg.debug {
log.SetLevel(zap.DebugLevel)
}
switch cfg.logLevel {
case "error":
log.SetLevel(zap.ErrorLevel)
case "warn":
log.SetLevel(zap.WarnLevel)
case "info":
log.SetLevel(zap.InfoLevel)
case "debug":
log.SetLevel(zap.DebugLevel)
default:
die("invalid log level: %v", cfg.logLevel)
}
pg.SetLogger(log)

if cfg.dataDir == "" {
Expand Down
16 changes: 16 additions & 0 deletions cmd/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type config struct {
listenAddress string
port string
stopListening bool
logLevel string
debug bool
}

Expand All @@ -68,7 +69,10 @@ func init() {
cmdProxy.PersistentFlags().StringVar(&cfg.listenAddress, "listen-address", "127.0.0.1", "proxy listening address")
cmdProxy.PersistentFlags().StringVar(&cfg.port, "port", "5432", "proxy listening port")
cmdProxy.PersistentFlags().BoolVar(&cfg.stopListening, "stop-listening", true, "stop listening on store error")
cmdProxy.PersistentFlags().StringVar(&cfg.logLevel, "log-level", "info", "debug, info (default), warn or error")
cmdProxy.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging")

cmdProxy.PersistentFlags().MarkDeprecated("debug", "use --log-level=debug instead")
}

func stderr(format string, a ...interface{}) {
Expand Down Expand Up @@ -318,6 +322,18 @@ func proxy(cmd *cobra.Command, args []string) {
if cfg.debug {
log.SetLevel(zap.DebugLevel)
}
switch cfg.logLevel {
case "error":
log.SetLevel(zap.ErrorLevel)
case "warn":
log.SetLevel(zap.WarnLevel)
case "info":
log.SetLevel(zap.InfoLevel)
case "debug":
log.SetLevel(zap.DebugLevel)
default:
die("invalid log level: %v", cfg.logLevel)
}
stdlog, _ := zwrap.Standardize(log, zap.DebugLevel)
pollon.SetLogger(stdlog)

Expand Down
18 changes: 17 additions & 1 deletion cmd/sentinel/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type config struct {
storeSkipTlsVerify bool
clusterName string
initialClusterSpecFile string
logLevel string
debug bool
}

Expand All @@ -76,7 +77,10 @@ func init() {
cmdSentinel.PersistentFlags().StringVar(&cfg.storeCAFile, "store-ca-file", "", "verify certificates of HTTPS-enabled store servers using this CA bundle")
cmdSentinel.PersistentFlags().StringVar(&cfg.clusterName, "cluster-name", "", "cluster name")
cmdSentinel.PersistentFlags().StringVar(&cfg.initialClusterSpecFile, "initial-cluster-spec", "", "a file providing the initial cluster specification, used only at cluster initialization, ignored if cluster is already initialized")
cmdSentinel.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging")
cmdSentinel.PersistentFlags().StringVar(&cfg.logLevel, "log-level", "info", "debug, info(default), warn or error")
cmdSentinel.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging (deprecated, use log-level instead)")

cmdSentinel.PersistentFlags().MarkDeprecated("debug", "use --log-level=debug instead")
}

var log = zap.New(zap.NewTextEncoder(), zap.AddCaller())
Expand Down Expand Up @@ -1544,6 +1548,18 @@ func sentinel(cmd *cobra.Command, args []string) {
if cfg.debug {
log.SetLevel(zap.DebugLevel)
}
switch cfg.logLevel {
case "error":
log.SetLevel(zap.ErrorLevel)
case "warn":
log.SetLevel(zap.WarnLevel)
case "info":
log.SetLevel(zap.InfoLevel)
case "debug":
log.SetLevel(zap.DebugLevel)
default:
die("invalid log level: %v", cfg.logLevel)
}
if cfg.clusterName == "" {
die("cluster name required")
}
Expand Down

0 comments on commit 0f82e68

Please sign in to comment.