diff --git a/main.go b/main.go index 694264b..26cf8c1 100644 --- a/main.go +++ b/main.go @@ -211,6 +211,7 @@ func run(c *cli.Context) error { Timeout: c.Duration("proxy.timeout"), }, }, + Writer: os.Stdout, } return plugin.Exec() diff --git a/plugin.go b/plugin.go index 6ea65d8..a3c752a 100644 --- a/plugin.go +++ b/plugin.go @@ -9,6 +9,7 @@ import ( "time" "github.com/appleboy/easyssh-proxy" + "io" ) const ( @@ -40,6 +41,7 @@ type ( // Plugin structure Plugin struct { Config Config + Writer io.Writer } ) @@ -121,10 +123,13 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) { } func (p Plugin) log(host string, message ...interface{}) { + if p.Writer == nil { + p.Writer = os.Stdout + } if count := len(p.Config.Host); count == 1 { - fmt.Printf("%s", fmt.Sprintln(message...)) + fmt.Fprintf(p.Writer, "%s", fmt.Sprintln(message...)) } else { - fmt.Printf("%s: %s", host, fmt.Sprintln(message...)) + fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...)) } }