mirror of https://github.com/docker/docs.git
Clearer writer name
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
parent
7281142868
commit
854219d44a
|
@ -12,7 +12,7 @@ import (
|
|||
func cmdConfig(c CommandLine, api libmachine.API) error {
|
||||
// Ensure that log messages always go to stderr when this command is
|
||||
// being run (it is intended to be run in a subshell)
|
||||
log.SetOut(os.Stderr)
|
||||
log.SetOutWriter(os.Stderr)
|
||||
|
||||
if len(c.Args()) != 1 {
|
||||
return ErrExpectedOneMachine
|
||||
|
|
|
@ -50,7 +50,7 @@ func cmdEnv(c CommandLine, api libmachine.API) error {
|
|||
|
||||
// Ensure that log messages always go to stderr when this command is
|
||||
// being run (it is intended to be run in a subshell)
|
||||
log.SetOut(os.Stderr)
|
||||
log.SetOutWriter(os.Stderr)
|
||||
|
||||
if c.Bool("unset") {
|
||||
shellCfg, err = shellCfgUnset(c, api)
|
||||
|
|
|
@ -81,13 +81,13 @@ func TestExecServer(t *testing.T) {
|
|||
logReader, logWriter := io.Pipe()
|
||||
|
||||
log.SetDebug(true)
|
||||
log.SetOut(logWriter)
|
||||
log.SetErr(logWriter)
|
||||
log.SetOutWriter(logWriter)
|
||||
log.SetErrWriter(logWriter)
|
||||
|
||||
defer func() {
|
||||
log.SetDebug(false)
|
||||
log.SetOut(os.Stdout)
|
||||
log.SetErr(os.Stderr)
|
||||
log.SetOutWriter(os.Stdout)
|
||||
log.SetErrWriter(os.Stderr)
|
||||
}()
|
||||
|
||||
stdoutReader, stdoutWriter := io.Pipe()
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
)
|
||||
|
||||
type FmtMachineLogger struct {
|
||||
out io.Writer
|
||||
err io.Writer
|
||||
outWriter io.Writer
|
||||
errWriter io.Writer
|
||||
debug bool
|
||||
history *HistoryRecorder
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ type FmtMachineLogger struct {
|
|||
// NewFmtMachineLogger creates a MachineLogger implementation used by the drivers
|
||||
func NewFmtMachineLogger() MachineLogger {
|
||||
return &FmtMachineLogger{
|
||||
out: os.Stdout,
|
||||
err: os.Stderr,
|
||||
outWriter: os.Stdout,
|
||||
errWriter: os.Stderr,
|
||||
debug: false,
|
||||
history: NewHistoryRecorder(),
|
||||
}
|
||||
|
@ -27,68 +27,68 @@ func (ml *FmtMachineLogger) SetDebug(debug bool) {
|
|||
ml.debug = debug
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) SetOut(out io.Writer) {
|
||||
ml.out = out
|
||||
func (ml *FmtMachineLogger) SetOutWriter(out io.Writer) {
|
||||
ml.outWriter = out
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) SetErr(err io.Writer) {
|
||||
ml.err = err
|
||||
func (ml *FmtMachineLogger) SetErrWriter(err io.Writer) {
|
||||
ml.errWriter = err
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Debug(args ...interface{}) {
|
||||
ml.history.Record(args...)
|
||||
if ml.debug {
|
||||
fmt.Fprintln(ml.err, args...)
|
||||
fmt.Fprintln(ml.errWriter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Debugf(fmtString string, args ...interface{}) {
|
||||
ml.history.Recordf(fmtString, args...)
|
||||
if ml.debug {
|
||||
fmt.Fprintf(ml.err, fmtString+"\n", args...)
|
||||
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Error(args ...interface{}) {
|
||||
ml.history.Record(args...)
|
||||
fmt.Fprintln(ml.err, args...)
|
||||
fmt.Fprintln(ml.errWriter, args...)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Errorf(fmtString string, args ...interface{}) {
|
||||
ml.history.Recordf(fmtString, args...)
|
||||
fmt.Fprintf(ml.err, fmtString+"\n", args...)
|
||||
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Info(args ...interface{}) {
|
||||
ml.history.Record(args...)
|
||||
fmt.Fprintln(ml.out, args...)
|
||||
fmt.Fprintln(ml.outWriter, args...)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Infof(fmtString string, args ...interface{}) {
|
||||
ml.history.Recordf(fmtString, args...)
|
||||
fmt.Fprintf(ml.out, fmtString+"\n", args...)
|
||||
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Fatal(args ...interface{}) {
|
||||
ml.history.Record(args...)
|
||||
fmt.Fprintln(ml.err, args...)
|
||||
fmt.Fprintln(ml.errWriter, args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Fatalf(fmtString string, args ...interface{}) {
|
||||
ml.history.Recordf(fmtString, args...)
|
||||
fmt.Fprintf(ml.err, fmtString+"\n", args...)
|
||||
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Warn(args ...interface{}) {
|
||||
ml.history.Record(args...)
|
||||
fmt.Fprintln(ml.out, args...)
|
||||
fmt.Fprintln(ml.outWriter, args...)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) Warnf(fmtString string, args ...interface{}) {
|
||||
ml.history.Recordf(fmtString, args...)
|
||||
fmt.Fprintf(ml.out, fmtString+"\n", args...)
|
||||
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
|
||||
}
|
||||
|
||||
func (ml *FmtMachineLogger) History() []string {
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
func captureOutput(testLogger MachineLogger, lambda func()) string {
|
||||
pipeReader, pipeWriter := io.Pipe()
|
||||
scanner := bufio.NewScanner(pipeReader)
|
||||
testLogger.SetOut(pipeWriter)
|
||||
testLogger.SetOutWriter(pipeWriter)
|
||||
go lambda()
|
||||
scanner.Scan()
|
||||
return scanner.Text()
|
||||
|
@ -21,7 +21,7 @@ func captureOutput(testLogger MachineLogger, lambda func()) string {
|
|||
func captureError(testLogger MachineLogger, lambda func()) string {
|
||||
pipeReader, pipeWriter := io.Pipe()
|
||||
scanner := bufio.NewScanner(pipeReader)
|
||||
testLogger.SetErr(pipeWriter)
|
||||
testLogger.SetErrWriter(pipeWriter)
|
||||
go lambda()
|
||||
scanner.Scan()
|
||||
return scanner.Text()
|
||||
|
@ -42,14 +42,14 @@ func TestSetDebugToFalse(t *testing.T) {
|
|||
|
||||
func TestSetOut(t *testing.T) {
|
||||
testLogger := NewFmtMachineLogger().(*FmtMachineLogger)
|
||||
testLogger.SetOut(ioutil.Discard)
|
||||
assert.Equal(t, ioutil.Discard, testLogger.out)
|
||||
testLogger.SetOutWriter(ioutil.Discard)
|
||||
assert.Equal(t, ioutil.Discard, testLogger.outWriter)
|
||||
}
|
||||
|
||||
func TestSetErr(t *testing.T) {
|
||||
testLogger := NewFmtMachineLogger().(*FmtMachineLogger)
|
||||
testLogger.SetErr(ioutil.Discard)
|
||||
assert.Equal(t, ioutil.Discard, testLogger.err)
|
||||
testLogger.SetErrWriter(ioutil.Discard)
|
||||
assert.Equal(t, ioutil.Discard, testLogger.errWriter)
|
||||
}
|
||||
|
||||
func TestDebug(t *testing.T) {
|
||||
|
|
|
@ -69,12 +69,12 @@ func SetDebug(debug bool) {
|
|||
logger.SetDebug(debug)
|
||||
}
|
||||
|
||||
func SetOut(out io.Writer) {
|
||||
logger.SetOut(out)
|
||||
func SetOutWriter(out io.Writer) {
|
||||
logger.SetOutWriter(out)
|
||||
}
|
||||
|
||||
func SetErr(err io.Writer) {
|
||||
logger.SetErr(err)
|
||||
func SetErrWriter(err io.Writer) {
|
||||
logger.SetErrWriter(err)
|
||||
}
|
||||
|
||||
func History() []string {
|
||||
|
|
|
@ -5,8 +5,8 @@ import "io"
|
|||
type MachineLogger interface {
|
||||
SetDebug(debug bool)
|
||||
|
||||
SetOut(io.Writer)
|
||||
SetErr(io.Writer)
|
||||
SetOutWriter(io.Writer)
|
||||
SetErrWriter(io.Writer)
|
||||
|
||||
Debug(args ...interface{})
|
||||
Debugf(fmtString string, args ...interface{})
|
||||
|
|
Loading…
Reference in New Issue