mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Plugins use parent loggers
This PR fixes various instances of plugins being launched without using the parent loggers. This meant that logs would not all go to the same output, break formatting etc.
This commit is contained in:
@@ -3,7 +3,7 @@ package command
|
||||
import (
|
||||
"strings"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/nomad/drivers/docker/docklog"
|
||||
"github.com/hashicorp/nomad/plugins/base"
|
||||
@@ -25,12 +25,19 @@ func (e *DockerLoggerPluginCommand) Synopsis() string {
|
||||
}
|
||||
|
||||
func (e *DockerLoggerPluginCommand) Run(args []string) int {
|
||||
logger := log.New(&log.LoggerOptions{
|
||||
Level: log.Trace,
|
||||
JSONFormat: true,
|
||||
Name: docklog.PluginName,
|
||||
})
|
||||
|
||||
plugin.Serve(&plugin.ServeConfig{
|
||||
HandshakeConfig: base.Handshake,
|
||||
Plugins: map[string]plugin.Plugin{
|
||||
docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(hclog.Default().Named(docklog.PluginName))),
|
||||
docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(logger)),
|
||||
},
|
||||
GRPCServer: plugin.DefaultGRPCServer,
|
||||
Logger: logger,
|
||||
})
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
|
||||
"github.com/hashicorp/nomad/drivers/shared/executor"
|
||||
@@ -32,24 +34,38 @@ func (e *ExecutorPluginCommand) Run(args []string) int {
|
||||
e.Ui.Error("json configuration not provided")
|
||||
return 1
|
||||
}
|
||||
|
||||
config := args[0]
|
||||
var executorConfig executor.ExecutorConfig
|
||||
if err := json.Unmarshal([]byte(config), &executorConfig); err != nil {
|
||||
return 1
|
||||
}
|
||||
stdo, err := os.OpenFile(executorConfig.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
|
||||
|
||||
f, err := os.OpenFile(executorConfig.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
e.Ui.Error(err.Error())
|
||||
return 1
|
||||
}
|
||||
|
||||
// Tee the logs to stderr and the file so that they are streamed to the
|
||||
// client
|
||||
out := io.MultiWriter(f, os.Stderr)
|
||||
|
||||
// Create the logger
|
||||
logger := log.New(&log.LoggerOptions{
|
||||
Level: hclog.LevelFromString(executorConfig.LogLevel),
|
||||
JSONFormat: true,
|
||||
Output: out,
|
||||
})
|
||||
|
||||
plugin.Serve(&plugin.ServeConfig{
|
||||
HandshakeConfig: base.Handshake,
|
||||
Plugins: executor.GetPluginMap(
|
||||
stdo,
|
||||
hclog.LevelFromString(executorConfig.LogLevel),
|
||||
logger,
|
||||
executorConfig.FSIsolation,
|
||||
),
|
||||
GRPCServer: plugin.DefaultGRPCServer,
|
||||
Logger: logger,
|
||||
})
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ func (e *LogMonPluginCommand) Run(args []string) int {
|
||||
"logmon": logmon.NewPlugin(logmon.NewLogMon(logger)),
|
||||
},
|
||||
GRPCServer: plugin.DefaultGRPCServer,
|
||||
Logger: logger,
|
||||
})
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user