Skip to content

Commit

Permalink
Merge pull request #206 from xinkonglili/weilili
Browse files Browse the repository at this point in the history
fix(hmq):Increased the log level of error #205
  • Loading branch information
chowyu12 authored Aug 30, 2024
2 parents a92de4c + 7f2cbaa commit 5d8c4be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
28 changes: 18 additions & 10 deletions broker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Config struct {
WsPort string `json:"wsPort"`
WsTLS bool `json:"wsTLS"`
TlsInfo TLSInfo `json:"tlsInfo"`
Debug bool `json:"debug"`
Debug string `json:"debug"`
Plugin Plugins `json:"plugins"`
UnixFilePath string `json:"unixFilePath"`
WindowsPipeName string `json:"windowsPipeName"`
Expand Down Expand Up @@ -87,12 +87,12 @@ func ConfigureConfig(args []string) (*Config, error) {
fs.BoolVar(&help, "help", false, "Show this message.")
fs.IntVar(&config.Worker, "w", 1024, "worker num to process message, perfer (client num)/10.")
fs.IntVar(&config.Worker, "worker", 1024, "worker num to process message, perfer (client num)/10.")
fs.StringVar(&config.HTTPPort, "httpport", "8080", "Port to listen on.")
fs.StringVar(&config.HTTPPort, "hp", "8080", "Port to listen on.")
fs.StringVar(&config.Port, "port", "", "Port to listen on.")
fs.StringVar(&config.Port, "p", "", "Port to listen on.")
fs.StringVar(&config.HTTPPort, "httpport", "", "Port to listen on.")
fs.StringVar(&config.HTTPPort, "hp", "", "Port to listen on.")
fs.StringVar(&config.Port, "port", "8090", "Port to listen on.")
fs.StringVar(&config.Port, "p", "8090", "Port to listen on.")
fs.StringVar(&config.UnixFilePath, "unixfilepath", "", "unix sock to listen on.")
fs.StringVar(&config.Host, "host", "0.0.0.0", "Network host to listen on")
fs.StringVar(&config.Host, "host", "127.0.0.1", "Network host to listen on")
fs.StringVar(&config.Cluster.Port, "cp", "", "Cluster port from which members can connect.")
fs.StringVar(&config.Cluster.Port, "clusterport", "", "Cluster port from which members can connect.")
fs.StringVar(&config.Router, "r", "", "Router who maintenance cluster info")
Expand All @@ -103,8 +103,8 @@ func ConfigureConfig(args []string) (*Config, error) {
fs.StringVar(&config.WsPath, "wspath", "", "path for ws to listen on")
fs.StringVar(&configFile, "config", "", "config file for hmq")
fs.StringVar(&configFile, "c", "", "config file for hmq")
fs.BoolVar(&config.Debug, "debug", false, "enable Debug logging.")
fs.BoolVar(&config.Debug, "d", false, "enable Debug logging.")
fs.StringVar(&config.Debug, "debug", "info", "enable Debug logging.")
fs.StringVar(&config.Debug, "d", "info", "enable Debug logging.")

fs.Bool("D", true, "enable Debug logging.")

Expand All @@ -120,7 +120,7 @@ func ConfigureConfig(args []string) (*Config, error) {
fs.Visit(func(f *flag.Flag) {
switch f.Name {
case "D":
config.Debug = true
config.Debug = "debug"
}
})

Expand All @@ -133,7 +133,15 @@ func ConfigureConfig(args []string) (*Config, error) {
}
}

if config.Debug {
//Set the debug level of logs
switch config.Debug {
case "debug":
log = logger.Debug().Named("broker")
case "info":
log = logger.Prod().Named("broker")
case "release":
log = logger.Release().Named("broker")
default:
log = logger.Debug().Named("broker")
}

Expand Down
17 changes: 17 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func NewProdLogger() (*zap.Logger, error) {
return logCfg.Build()
}

// NewReleaseLogger return a logger for production builds
func NewReleaseLogger() (*zap.Logger, error) {
logCfg := zap.NewProductionConfig()
logCfg.DisableStacktrace = true
logCfg.Level = zap.NewAtomicLevelAt(zap.ErrorLevel)
logCfg.EncoderConfig = encoderCfg
return logCfg.Build()
}

func Prod() *zap.Logger {

l, _ := NewProdLogger()
Expand All @@ -54,6 +63,14 @@ func Debug() *zap.Logger {
return instance
}

func Release() *zap.Logger {

l, _ := NewReleaseLogger()
instance = l

return instance
}

func Get() *zap.Logger {
if instance == nil {
l, _ := NewProdLogger()
Expand Down

0 comments on commit 5d8c4be

Please sign in to comment.