From 22454738af914913e5fed8caef8b4865407b4483 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 3 May 2017 18:32:11 +0200 Subject: [PATCH] application-wide logging through Logger interface --- cmd/main.go | 8 ++++++++ scratchpad/chunker/main.go | 6 +++--- sshbytestream/ssh.go | 1 - 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index a776d86..c424daa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -11,9 +11,14 @@ import ( "time" ) +type Logger interface { + Printf(format string, v ...interface{}) +} + var conf Config var runner *jobrun.JobRunner var logFlags int = log.LUTC | log.Ldate | log.Ltime +var defaultLog Logger func main() { @@ -26,6 +31,9 @@ func main() { cli.StringFlag{Name: "config"}, } app.Before = func(c *cli.Context) (err error) { + + defaultLog = log.New(os.Stderr, "", logFlags) + if !c.GlobalIsSet("config") { return errors.New("config flag not set") } diff --git a/scratchpad/chunker/main.go b/scratchpad/chunker/main.go index 0f160f0..c7a3d42 100644 --- a/scratchpad/chunker/main.go +++ b/scratchpad/chunker/main.go @@ -7,8 +7,8 @@ import ( // "bytes" _ "bufio" // "strings" - "fmt" "io" + "log" "os" _ "time" ) @@ -44,7 +44,7 @@ func main() { panic(err) } - fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", chunker.ChunkCount) + log.Printf("Chunk Count: %d\n", chunker.ChunkCount) case *mode == "outgoing": @@ -72,7 +72,7 @@ func main() { conn.Close() - fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", unchunker.ChunkCount) + log.Printf("Chunk Count: %d\n", unchunker.ChunkCount) os.Exit(0) diff --git a/sshbytestream/ssh.go b/sshbytestream/ssh.go index ac18c35..1158418 100644 --- a/sshbytestream/ssh.go +++ b/sshbytestream/ssh.go @@ -115,7 +115,6 @@ func Outgoing(remote SSHTransport) (conn io.ReadWriteCloser, err error) { Stderr: stderrBuf.Bytes(), WaitErr: err, } - // fmt.Fprintf(os.Stderr, "ssh conn wait err: %#v\n", f.SSHCommandError.(Error)) } else { f.SSHCommandError = nil }