mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
web: use default logger (#1577)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
980b772801
commit
e0c9234c0e
@ -55,7 +55,7 @@ func (s *service) genSrv() *registry.Service {
|
|||||||
if len(s.opts.Address) > 0 {
|
if len(s.opts.Address) > 0 {
|
||||||
host, port, err = net.SplitHostPort(s.opts.Address)
|
host, port, err = net.SplitHostPort(s.opts.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logger.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,13 +65,13 @@ func (s *service) genSrv() *registry.Service {
|
|||||||
if len(s.opts.Advertise) > 0 {
|
if len(s.opts.Advertise) > 0 {
|
||||||
host, port, err = net.SplitHostPort(s.opts.Address)
|
host, port, err = net.SplitHostPort(s.opts.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logger.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := maddr.Extract(host)
|
addr, err := maddr.Extract(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logger.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Count(addr, ":") > 0 {
|
if strings.Count(addr, ":") > 0 {
|
||||||
@ -128,8 +128,8 @@ func (s *service) register() error {
|
|||||||
|
|
||||||
// use RegisterCheck func before register
|
// use RegisterCheck func before register
|
||||||
if err := s.opts.RegisterCheck(s.opts.Context); err != nil {
|
if err := s.opts.RegisterCheck(s.opts.Context); err != nil {
|
||||||
if logger.V(logger.ErrorLevel, log) {
|
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||||
log.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err)
|
logger.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -195,8 +195,8 @@ func (s *service) start() error {
|
|||||||
if s.static {
|
if s.static {
|
||||||
_, err := os.Stat(static)
|
_, err := os.Stat(static)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if logger.V(logger.InfoLevel, log) {
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
log.Infof("Enabling static file serving from %s", static)
|
logger.Infof("Enabling static file serving from %s", static)
|
||||||
}
|
}
|
||||||
s.mux.Handle("/", http.FileServer(http.Dir(static)))
|
s.mux.Handle("/", http.FileServer(http.Dir(static)))
|
||||||
}
|
}
|
||||||
@ -229,8 +229,8 @@ func (s *service) start() error {
|
|||||||
ch <- l.Close()
|
ch <- l.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if logger.V(logger.InfoLevel, log) {
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
log.Infof("Listening on %v", l.Addr().String())
|
logger.Infof("Listening on %v", l.Addr().String())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -253,8 +253,8 @@ func (s *service) stop() error {
|
|||||||
s.exit <- ch
|
s.exit <- ch
|
||||||
s.running = false
|
s.running = false
|
||||||
|
|
||||||
if logger.V(logger.InfoLevel, log) {
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
log.Info("Stopping")
|
logger.Info("Stopping")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fn := range s.opts.AfterStop {
|
for _, fn := range s.opts.AfterStop {
|
||||||
@ -419,13 +419,13 @@ func (s *service) Run() error {
|
|||||||
select {
|
select {
|
||||||
// wait on kill signal
|
// wait on kill signal
|
||||||
case sig := <-ch:
|
case sig := <-ch:
|
||||||
if logger.V(logger.InfoLevel, log) {
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
log.Infof("Received signal %s", sig)
|
logger.Infof("Received signal %s", sig)
|
||||||
}
|
}
|
||||||
// wait on context cancel
|
// wait on context cancel
|
||||||
case <-s.opts.Context.Done():
|
case <-s.opts.Context.Done():
|
||||||
if logger.V(logger.InfoLevel, log) {
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
log.Info("Received context shutdown")
|
logger.Info("Received context shutdown")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/micro/go-micro/v2/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service is a web service with service discovery built in
|
// Service is a web service with service discovery built in
|
||||||
@ -38,8 +37,6 @@ var (
|
|||||||
// static directory
|
// static directory
|
||||||
DefaultStaticDir = "html"
|
DefaultStaticDir = "html"
|
||||||
DefaultRegisterCheck = func(context.Context) error { return nil }
|
DefaultRegisterCheck = func(context.Context) error { return nil }
|
||||||
|
|
||||||
log = logger.NewHelper(logger.DefaultLogger).WithFields(map[string]interface{}{"service": "web"})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewService returns a new web.Service
|
// NewService returns a new web.Service
|
||||||
|
Loading…
Reference in New Issue
Block a user