From d502e2f58abf344c50ceb4dc421cb9b248344b2b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 15:46:09 +0000 Subject: [PATCH] fix breaks --- debug/log/log.go | 2 +- debug/log/options.go | 9 +++++++++ debug/service/log.go | 31 +++++++++++++------------------ debug/service/service.go | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/debug/log/log.go b/debug/log/log.go index 9425ff19..918d0c55 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -174,6 +174,6 @@ func SetPrefix(p string) { } // Set service name -func Name(name string) { +func SetName(name string) { prefix = fmt.Sprintf("[%s]", name) } diff --git a/debug/log/options.go b/debug/log/options.go index 03dece38..0d83394b 100644 --- a/debug/log/options.go +++ b/debug/log/options.go @@ -7,10 +7,19 @@ type Option func(*Options) // Options are logger options type Options struct { + // Name of the log + Name string // Size is the size of ring buffer Size int } +// Name of the log +func Name(n string) Option { + return func(o *Options) { + o.Name = n + } +} + // Size sets the size of the ring buffer func Size(s int) Option { return func(o *Options) { diff --git a/debug/service/log.go b/debug/service/log.go index 7a9aabc5..3508874c 100644 --- a/debug/service/log.go +++ b/debug/service/log.go @@ -1,13 +1,8 @@ package service import ( - "context" - "fmt" - "time" - - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/debug" "github.com/micro/go-micro/debug/log" - pb "github.com/micro/go-micro/debug/service/proto" ) type serviceLog struct { @@ -23,7 +18,7 @@ func (s *serviceLog) Read(opts ...log.ReadOption) []log.Record { } // stream the records until nothing is left var records []log.Record - for _, record := range stream { + for record := range stream { records = append(records, record) } return records @@ -35,30 +30,30 @@ func (s *serviceLog) Write(r log.Record) { } // Stream log records -func (s *serviceLog) Stream(ch chan bool) (<-chan log.Record, chan bool) { +func (s *serviceLog) Stream() (<-chan log.Record, chan bool) { stop := make(chan bool) stream, err := s.Client.Log(log.Stream(true)) if err != nil { // return a closed stream - stream = make(chan log.Record) - close(stream) - return stream, stop + deadStream := make(chan log.Record) + close(deadStream) + return deadStream, stop } - // stream the records until nothing is left + newStream := make(chan log.Record, 128) + go func() { - var records []log.Record - for _, record := range stream { + for { select { - case stream <- record: + case rec := <-stream: + newStream <- rec case <-stop: return } } }() - // return the stream - return stream, stop + return newStream, stop } // NewLog returns a new log interface @@ -75,7 +70,7 @@ func NewLog(opts ...log.Option) log.Log { name = debug.DefaultName } - return serviceLog{ + return &serviceLog{ Client: newDebugClient(name), } } diff --git a/debug/service/service.go b/debug/service/service.go index 7527127a..7d73c753 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -18,7 +18,7 @@ type debugClient struct { } // NewDebug provides Debug service implementation -func newDebugClient(name string) *debug { +func newDebugClient(name string) *debugClient { // create default client cli := client.DefaultClient