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
func Name(name string) {
func SetName(name string) {
prefix = fmt.Sprintf("[%s]", name)
}

View File

@ -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) {

View File

@ -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),
}
}

View File

@ -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