micro/debug/log/default.go
2019-12-01 13:16:43 +00:00

49 lines
818 B
Go

package log
import (
"fmt"
golog "log"
"github.com/micro/go-micro/debug/buffer"
)
var (
// DefaultSize of the logger buffer
DefaultSize = 1000
)
// defaultLogger is default micro logger
type defaultLogger struct {
*buffer.Buffer
}
// NewLogger returns default Logger with
func NewLogger(opts ...Option) Logger {
// get default options
options := DefaultOptions()
// apply requested options
for _, o := range opts {
o(&options)
}
return &defaultLogger{
Buffer: buffer.New(options.Size),
}
}
// Write writes log into logger
func (l *defaultLogger) Write(v ...interface{}) {
l.log(fmt.Sprint(v...))
golog.Print(v...)
}
// Read reads logs from the logger
func (l *defaultLogger) Read(n int) []interface{} {
return l.Get(n)
}
func (l *defaultLogger) log(entry string) {
l.Buffer.Put(entry)
}