Skip to content

Commit

Permalink
nsqlookupd: typed log-level
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Mar 2, 2019
1 parent 05668cf commit 179052e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
5 changes: 3 additions & 2 deletions apps/nsqlookupd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func nsqlookupdFlagSet(opts *nsqlookupd.Options) *flag.FlagSet {
flagSet.String("config", "", "path to config file")
flagSet.Bool("version", false, "print version string")

flagSet.String("log-level", "info", "set log verbosity: debug, info, warn, error, or fatal")
logLevel := opts.LogLevel
flagSet.Var(&logLevel, "log-level", "set log verbosity: debug, info, warn, error, or fatal")
flagSet.String("log-prefix", "[nsqlookupd] ", "log message prefix")
flagSet.Bool("verbose", false, "deprecated in favor of log-level")
flagSet.Bool("verbose", false, "[deprecated] has no effect, use --log-level")

flagSet.String("tcp-address", opts.TCPAddress, "<addr>:<port> to listen on for TCP clients")
flagSet.String("http-address", opts.HTTPAddress, "<addr>:<port> to listen on for HTTP clients")
Expand Down
2 changes: 1 addition & 1 deletion nsqlookupd/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ const (
)

func (n *NSQLookupd) logf(level lg.LogLevel, f string, args ...interface{}) {
lg.Logf(n.opts.Logger, n.opts.logLevel, level, f, args...)
lg.Logf(n.opts.Logger, n.opts.LogLevel, level, f, args...)
}
12 changes: 3 additions & 9 deletions nsqlookupd/nsqlookupd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"

"github.com/nsqio/nsq/internal/http_api"
"github.com/nsqio/nsq/internal/lg"
"github.com/nsqio/nsq/internal/protocol"
"github.com/nsqio/nsq/internal/util"
"github.com/nsqio/nsq/internal/version"
Expand All @@ -27,19 +26,14 @@ func New(opts *Options) (*NSQLookupd, error) {
if opts.Logger == nil {
opts.Logger = log.New(os.Stderr, opts.LogPrefix, log.Ldate|log.Ltime|log.Lmicroseconds)
}
n := &NSQLookupd{
l := &NSQLookupd{
opts: opts,
DB: NewRegistrationDB(),
}

var err error
opts.logLevel, err = lg.ParseLogLevel(opts.LogLevel, opts.Verbose)
if err != nil {
return nil, fmt.Errorf("failed to parse log level (%s) - %s", opts.LogLevel, err)
}
l.logf(LOG_INFO, version.String("nsqlookupd"))

n.logf(LOG_INFO, version.String("nsqlookupd"))
return n, nil
return l, nil
}

// Main starts an instance of nsqlookupd and returns an
Expand Down
8 changes: 3 additions & 5 deletions nsqlookupd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
)

type Options struct {
LogLevel string `flag:"log-level"`
LogPrefix string `flag:"log-prefix"`
Verbose bool `flag:"verbose"` // for backwards compatibility
LogLevel lg.LogLevel `flag:"log-level"`
LogPrefix string `flag:"log-prefix"`
Logger Logger
logLevel lg.LogLevel // private, not really an option

TCPAddress string `flag:"tcp-address"`
HTTPAddress string `flag:"http-address"`
Expand All @@ -31,7 +29,7 @@ func NewOptions() *Options {

return &Options{
LogPrefix: "[nsqlookupd] ",
LogLevel: "info",
LogLevel: lg.INFO,
TCPAddress: "0.0.0.0:4160",
HTTPAddress: "0.0.0.0:4161",
BroadcastAddress: hostname,
Expand Down

0 comments on commit 179052e

Please sign in to comment.