5 Commits

Author SHA1 Message Date
Eric Pearson
5d8c4bee66 Merge pull request #206 from xinkonglili/weilili
fix(hmq):Increased the log level of error #205
2024-08-30 18:04:50 +08:00
wei_lilitw
7f2cbaaf20 fix(hmq):Set a higher debug level for logs to avoid printing too much log information and interfering with debugging 2024-05-27 11:03:48 +08:00
Eric Pearson
a92de4c9e8 Merge pull request #204 from xinkonglili/weilili
fix(broker):Added file removal for unix sock communication #203
2024-05-24 09:38:39 +08:00
wei_lilitw
646f13199d fix(broker):fix unix sock file not be removed 2024-05-23 17:22:29 +08:00
wei_lilitw
67594b07ef fix(broker):fix unix sock file not be removed 2024-05-23 17:21:21 +08:00
3 changed files with 36 additions and 10 deletions

View File

@@ -284,6 +284,7 @@ func (b *Broker) StartUnixSocketClientListening(socketPath string, unixSocket bo
for { for {
if unixSocket { if unixSocket {
if FileExist(socketPath) { if FileExist(socketPath) {
err = os.Remove(socketPath)
if err != nil { if err != nil {
log.Error("Remove Unix socketPath ", zap.Error(err)) log.Error("Remove Unix socketPath ", zap.Error(err))
} }

View File

@@ -31,7 +31,7 @@ type Config struct {
WsPort string `json:"wsPort"` WsPort string `json:"wsPort"`
WsTLS bool `json:"wsTLS"` WsTLS bool `json:"wsTLS"`
TlsInfo TLSInfo `json:"tlsInfo"` TlsInfo TLSInfo `json:"tlsInfo"`
Debug bool `json:"debug"` Debug string `json:"debug"`
Plugin Plugins `json:"plugins"` Plugin Plugins `json:"plugins"`
UnixFilePath string `json:"unixFilePath"` UnixFilePath string `json:"unixFilePath"`
WindowsPipeName string `json:"windowsPipeName"` WindowsPipeName string `json:"windowsPipeName"`
@@ -87,12 +87,12 @@ func ConfigureConfig(args []string) (*Config, error) {
fs.BoolVar(&help, "help", false, "Show this message.") 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, "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.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, "httpport", "", "Port to listen on.")
fs.StringVar(&config.HTTPPort, "hp", "8080", "Port to listen on.") fs.StringVar(&config.HTTPPort, "hp", "", "Port to listen on.")
fs.StringVar(&config.Port, "port", "", "Port to listen on.") fs.StringVar(&config.Port, "port", "8090", "Port to listen on.")
fs.StringVar(&config.Port, "p", "", "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.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, "cp", "", "Cluster port from which members can connect.")
fs.StringVar(&config.Cluster.Port, "clusterport", "", "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") fs.StringVar(&config.Router, "r", "", "Router who maintenance cluster info")
@@ -103,8 +103,8 @@ func ConfigureConfig(args []string) (*Config, error) {
fs.StringVar(&config.WsPath, "wspath", "", "path for ws to listen on") fs.StringVar(&config.WsPath, "wspath", "", "path for ws to listen on")
fs.StringVar(&configFile, "config", "", "config file for hmq") fs.StringVar(&configFile, "config", "", "config file for hmq")
fs.StringVar(&configFile, "c", "", "config file for hmq") fs.StringVar(&configFile, "c", "", "config file for hmq")
fs.BoolVar(&config.Debug, "debug", false, "enable Debug logging.") fs.StringVar(&config.Debug, "debug", "info", "enable Debug logging.")
fs.BoolVar(&config.Debug, "d", false, "enable Debug logging.") fs.StringVar(&config.Debug, "d", "info", "enable Debug logging.")
fs.Bool("D", true, "enable Debug logging.") fs.Bool("D", true, "enable Debug logging.")
@@ -120,7 +120,7 @@ func ConfigureConfig(args []string) (*Config, error) {
fs.Visit(func(f *flag.Flag) { fs.Visit(func(f *flag.Flag) {
switch f.Name { switch f.Name {
case "D": case "D":
config.Debug = true config.Debug = "debug"
} }
}) })
@@ -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") log = logger.Debug().Named("broker")
} }

View File

@@ -38,6 +38,15 @@ func NewProdLogger() (*zap.Logger, error) {
return logCfg.Build() 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 { func Prod() *zap.Logger {
l, _ := NewProdLogger() l, _ := NewProdLogger()
@@ -54,6 +63,14 @@ func Debug() *zap.Logger {
return instance return instance
} }
func Release() *zap.Logger {
l, _ := NewReleaseLogger()
instance = l
return instance
}
func Get() *zap.Logger { func Get() *zap.Logger {
if instance == nil { if instance == nil {
l, _ := NewProdLogger() l, _ := NewProdLogger()