mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
27bd6842f8
Logging plugins use the same HTTP interface as other plugins for basic command operations meanwhile actual logging operations are handled (on Unix) via a fifo. The plugin interface looks like so: ```go type loggingPlugin interface { StartLogging(fifoPath string, loggingContext Context) error StopLogging(fifoPath) ``` This means a plugin must implement `LoggingDriver.StartLogging` and `LoggingDriver.StopLogging` endpoints and be able to consume the passed in fifo. Logs are sent via stream encoder to the fifo encoded with protobuf. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
107 lines
1.8 KiB
Go
107 lines
1.8 KiB
Go
package logger
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
)
|
|
|
|
type client interface {
|
|
Call(string, interface{}, interface{}) error
|
|
Stream(string, interface{}) (io.ReadCloser, error)
|
|
}
|
|
|
|
type logPluginProxy struct {
|
|
client
|
|
}
|
|
|
|
type logPluginProxyStartLoggingRequest struct {
|
|
File string
|
|
Info Info
|
|
}
|
|
|
|
type logPluginProxyStartLoggingResponse struct {
|
|
Err string
|
|
}
|
|
|
|
func (pp *logPluginProxy) StartLogging(file string, info Info) (err error) {
|
|
var (
|
|
req logPluginProxyStartLoggingRequest
|
|
ret logPluginProxyStartLoggingResponse
|
|
)
|
|
|
|
req.File = file
|
|
req.Info = info
|
|
if err = pp.Call("LogDriver.StartLogging", req, &ret); err != nil {
|
|
return
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
err = errors.New(ret.Err)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type logPluginProxyStopLoggingRequest struct {
|
|
File string
|
|
}
|
|
|
|
type logPluginProxyStopLoggingResponse struct {
|
|
Err string
|
|
}
|
|
|
|
func (pp *logPluginProxy) StopLogging(file string) (err error) {
|
|
var (
|
|
req logPluginProxyStopLoggingRequest
|
|
ret logPluginProxyStopLoggingResponse
|
|
)
|
|
|
|
req.File = file
|
|
if err = pp.Call("LogDriver.StopLogging", req, &ret); err != nil {
|
|
return
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
err = errors.New(ret.Err)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type logPluginProxyCapabilitiesResponse struct {
|
|
Cap Capability
|
|
Err string
|
|
}
|
|
|
|
func (pp *logPluginProxy) Capabilities() (cap Capability, err error) {
|
|
var (
|
|
ret logPluginProxyCapabilitiesResponse
|
|
)
|
|
|
|
if err = pp.Call("LogDriver.Capabilities", nil, &ret); err != nil {
|
|
return
|
|
}
|
|
|
|
cap = ret.Cap
|
|
|
|
if ret.Err != "" {
|
|
err = errors.New(ret.Err)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type logPluginProxyReadLogsRequest struct {
|
|
Info Info
|
|
Config ReadConfig
|
|
}
|
|
|
|
func (pp *logPluginProxy) ReadLogs(info Info, config ReadConfig) (stream io.ReadCloser, err error) {
|
|
var (
|
|
req logPluginProxyReadLogsRequest
|
|
)
|
|
|
|
req.Info = info
|
|
req.Config = config
|
|
return pp.Stream("LogDriver.ReadLogs", req)
|
|
}
|