micro/debug/log/kubernetes/stream.go

41 lines
591 B
Go
Raw Normal View History

package kubernetes
import "github.com/micro/go-micro/debug/log"
import (
"encoding/json"
"fmt"
"os"
)
2019-12-17 20:24:01 +03:00
func write(l log.Record) error {
m, err := json.Marshal(l)
if err == nil {
_, err := fmt.Fprintf(os.Stderr, "%s", m)
return err
}
2019-12-17 20:24:01 +03:00
return err
}
type klogStreamer struct {
2019-12-17 21:34:21 +03:00
// the k8s log stream
2019-12-17 20:24:01 +03:00
streamChan chan log.Record
2019-12-17 21:34:21 +03:00
// the stop chan
stop chan bool
2019-12-17 20:24:01 +03:00
}
func (k *klogStreamer) Chan() <-chan log.Record {
return k.streamChan
}
func (k *klogStreamer) Stop() error {
2019-12-17 21:34:21 +03:00
select {
case <-k.stop:
return nil
default:
close(k.stop)
close(k.streamChan)
}
2019-12-17 20:24:01 +03:00
return nil
}