fix breaks

This commit is contained in:
Asim Aslam 2019-12-17 15:46:09 +00:00
parent bc30efcf70
commit d502e2f58a
4 changed files with 24 additions and 20 deletions

View File

@ -174,6 +174,6 @@ func SetPrefix(p string) {
} }
// Set service name // Set service name
func Name(name string) { func SetName(name string) {
prefix = fmt.Sprintf("[%s]", name) prefix = fmt.Sprintf("[%s]", name)
} }

View File

@ -7,10 +7,19 @@ type Option func(*Options)
// Options are logger options // Options are logger options
type Options struct { type Options struct {
// Name of the log
Name string
// Size is the size of ring buffer // Size is the size of ring buffer
Size int 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 // Size sets the size of the ring buffer
func Size(s int) Option { func Size(s int) Option {
return func(o *Options) { return func(o *Options) {

View File

@ -1,13 +1,8 @@
package service package service
import ( import (
"context" "github.com/micro/go-micro/debug"
"fmt"
"time"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/debug/log" "github.com/micro/go-micro/debug/log"
pb "github.com/micro/go-micro/debug/service/proto"
) )
type serviceLog struct { type serviceLog struct {
@ -23,7 +18,7 @@ func (s *serviceLog) Read(opts ...log.ReadOption) []log.Record {
} }
// stream the records until nothing is left // stream the records until nothing is left
var records []log.Record var records []log.Record
for _, record := range stream { for record := range stream {
records = append(records, record) records = append(records, record)
} }
return records return records
@ -35,30 +30,30 @@ func (s *serviceLog) Write(r log.Record) {
} }
// Stream log records // 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) stop := make(chan bool)
stream, err := s.Client.Log(log.Stream(true)) stream, err := s.Client.Log(log.Stream(true))
if err != nil { if err != nil {
// return a closed stream // return a closed stream
stream = make(chan log.Record) deadStream := make(chan log.Record)
close(stream) close(deadStream)
return stream, stop return deadStream, stop
} }
// stream the records until nothing is left newStream := make(chan log.Record, 128)
go func() { go func() {
var records []log.Record for {
for _, record := range stream {
select { select {
case stream <- record: case rec := <-stream:
newStream <- rec
case <-stop: case <-stop:
return return
} }
} }
}() }()
// return the stream return newStream, stop
return stream, stop
} }
// NewLog returns a new log interface // NewLog returns a new log interface
@ -75,7 +70,7 @@ func NewLog(opts ...log.Option) log.Log {
name = debug.DefaultName name = debug.DefaultName
} }
return serviceLog{ return &serviceLog{
Client: newDebugClient(name), Client: newDebugClient(name),
} }
} }

View File

@ -18,7 +18,7 @@ type debugClient struct {
} }
// NewDebug provides Debug service implementation // NewDebug provides Debug service implementation
func newDebugClient(name string) *debug { func newDebugClient(name string) *debugClient {
// create default client // create default client
cli := client.DefaultClient cli := client.DefaultClient