1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Split reader interface from logger interface

Implement new reader interface on jsonfile.
Moves jsonlog decoding from daemon to jsonfile logger.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2015-07-03 09:50:06 -04:00
parent d241d2f36c
commit c0391bf554
13 changed files with 726 additions and 266 deletions

View file

@ -2,11 +2,19 @@ package logger
import (
"errors"
"io"
"time"
"github.com/docker/docker/pkg/timeutils"
)
var ReadLogsNotSupported = errors.New("configured logging reader does not support reading")
// ErrReadLogsNotSupported is returned when the logger does not support reading logs
var ErrReadLogsNotSupported = errors.New("configured logging reader does not support reading")
const (
// TimeFormat is the time format used for timestamps sent to log readers
TimeFormat = timeutils.RFC3339NanoFixed
logWatcherBufferSize = 4096
)
// Message is datastructure that represents record from some container
type Message struct {
@ -16,14 +24,51 @@ type Message struct {
Timestamp time.Time
}
// Logger is interface for docker logging drivers
// Logger is the interface for docker logging drivers
type Logger interface {
Log(*Message) error
Name() string
Close() error
}
//Reader is an interface for docker logging drivers that support reading
type Reader interface {
ReadLog(args ...string) (io.Reader, error)
// ReadConfig is the configuration passed into ReadLogs
type ReadConfig struct {
Since time.Time
Tail int
Follow bool
}
// LogReader is the interface for reading log messages for loggers that support reading
type LogReader interface {
// Read logs from underlying logging backend
ReadLogs(ReadConfig) *LogWatcher
}
// LogWatcher is used when consuming logs read from the LogReader interface
type LogWatcher struct {
// For sending log messages to a reader
Msg chan *Message
// For sending error messages that occur while while reading logs
Err chan error
closeNotifier chan struct{}
}
// NewLogWatcher returns a new LogWatcher.
func NewLogWatcher() *LogWatcher {
return &LogWatcher{
Msg: make(chan *Message, logWatcherBufferSize),
Err: make(chan error, 1),
closeNotifier: make(chan struct{}),
}
}
// Close notifies the underlying log reader to stop
func (w *LogWatcher) Close() {
close(w.closeNotifier)
}
// WatchClose returns a channel receiver that receives notification when the watcher has been closed
// This should only be called from one goroutine
func (w *LogWatcher) WatchClose() <-chan struct{} {
return w.closeNotifier
}