Plugins update log (#47)

* modify

* update

* add acl

* add feature

* update dockerfile

* add deploy

* update

* update

* plugins

* plugins

* update

* update

* update

* fixed

* remove

* fixed

* add log

* update

* fixed

* update

* fix config

* add http api

* add http api

* resp

* add config for work chan

* update

* fixed

* update

* disable trace

* fixed

* change acl

* fixed

* fixed res

* dd

* dd

* ddd

* dd

* update

* fixed

* update

* add

* fixed

* update key

* add log

* update

* format

* update

* update auth

* update

* update readme

* added

* update

* fixed

* fixed

* fix

* upade

* update

* update

* update
This commit is contained in:
joy.zhou
2019-07-25 16:01:40 +08:00
committed by GitHub
parent c6b1f1db42
commit 4c5a48a44b
4 changed files with 52 additions and 19 deletions

View File

@@ -62,6 +62,10 @@ func newMessagePool() []chan *Message {
}
func NewBroker(config *Config) (*Broker, error) {
if config == nil {
config = DefaultConfig
}
b := &Broker{
id: GenUniqueId(),
config: config,

View File

@@ -54,7 +54,7 @@ var DefaultConfig *Config = &Config{
}
var (
log *zap.Logger
log = logger.Prod().Named("broker")
)
func showHelp() {
@@ -118,8 +118,9 @@ func ConfigureConfig(args []string) (*Config, error) {
}
}
logger.InitLogger(config.Debug)
log = logger.Get().Named("Broker")
if config.Debug {
log = logger.Debug().Named("broker")
}
if err := config.check(); err != nil {
return nil, err

29
cmd/broker/main.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import (
"log"
"os"
"os/signal"
"github.com/fhmq/hmq/broker"
)
func main() {
b, err := broker.NewBroker(nil)
if err != nil {
log.Fatal("New Broker error: ", err)
}
b.Start()
s := waitForSignal()
log.Println("signal received, broker closed.", s)
}
func waitForSignal() os.Signal {
signalChan := make(chan os.Signal, 1)
defer close(signalChan)
signal.Notify(signalChan, os.Kill, os.Interrupt)
s := <-signalChan
signal.Stop(signalChan)
return s
}

View File

@@ -29,28 +29,27 @@ func NewProdLogger() (*zap.Logger, error) {
return logCfg.Build()
}
func InitLogger(debug bool) {
var err error
var log *zap.Logger
if debug {
log, err = NewDevLogger()
} else {
log, err = NewProdLogger()
}
if err != nil {
panic("Unable to create a logger.")
}
defer log.Sync()
func Prod() *zap.Logger {
log.Debug("Logger initialization succeeded")
instance = log.Named("hmq")
l, _ := NewProdLogger()
instance = l
return instance
}
func Debug() *zap.Logger {
l, _ := NewDevLogger()
instance = l
return instance
}
// Get return a *zap.Logger instance
func Get() *zap.Logger {
if instance == nil {
l, _ := NewProdLogger()
return l
instance = l
}
return instance
}