First commit for Kubernetes logger

This commit is contained in:
Jake Sanders 2019-12-17 12:11:26 +00:00
parent e95f44d3f8
commit 0415ead504
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,23 @@
// Package kubernetes is a logger implementing (github.com/micro/go-micro/debug/log).Log
package kubernetes
import (
"github.com/micro/go-micro/debug/log"
)
type klog struct{}
func (k *klog) Read(...log.ReadOption) []log.Record { return nil }
func (k *klog) Write(log.Record) {}
func (k *klog) Stream(stop chan bool) <-chan log.Record {
c := make(chan log.Record)
go close(c)
return c
}
// New returns a configured Kubernetes logger
func New() log.Log {
return &klog{}
}

View File

@ -0,0 +1,44 @@
package kubernetes
import (
"bytes"
"io"
"os"
"testing"
"time"
"github.com/micro/go-micro/debug/log"
"github.com/stretchr/testify/assert"
)
func TestKubernetes(t *testing.T) {
k := New()
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
s := os.Stderr
os.Stderr = w
meta := make(map[string]string)
meta["foo"] = "bar"
k.Write(log.Record{
Timestamp: time.Unix(0, 0),
Value: "Test log entry",
Metadata: meta,
})
b := &bytes.Buffer{}
w.Close()
io.Copy(b, r)
os.Stderr = s
assert.Equal(t, "Test log entry", b.String(), "Write was not equal")
assert.Nil(t, k.Read(), "Read should be unimplemented")
stream := k.Stream(make(chan bool))
records := []log.Record{}
for s := range stream {
records = append(records, s)
}
assert.Equal(t, 0, len(records), "Stream should be unimplemented")
}