Customization of logger output destination

This commit is contained in:
Josh Komoroske 2018-02-27 10:27:41 -08:00
parent 8bfc58f9d0
commit 6691360868
2 changed files with 8 additions and 2 deletions

View File

@ -211,6 +211,7 @@ func run(c *cli.Context) error {
Timeout: c.Duration("proxy.timeout"),
},
},
Writer: os.Stdout,
}
return plugin.Exec()

View File

@ -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...))
}
}