application-wide logging through Logger interface

This commit is contained in:
Christian Schwarz 2017-05-03 18:32:11 +02:00
parent 1e7b29bdc5
commit 22454738af
3 changed files with 11 additions and 4 deletions

View File

@ -11,9 +11,14 @@ import (
"time" "time"
) )
type Logger interface {
Printf(format string, v ...interface{})
}
var conf Config var conf Config
var runner *jobrun.JobRunner var runner *jobrun.JobRunner
var logFlags int = log.LUTC | log.Ldate | log.Ltime var logFlags int = log.LUTC | log.Ldate | log.Ltime
var defaultLog Logger
func main() { func main() {
@ -26,6 +31,9 @@ func main() {
cli.StringFlag{Name: "config"}, cli.StringFlag{Name: "config"},
} }
app.Before = func(c *cli.Context) (err error) { app.Before = func(c *cli.Context) (err error) {
defaultLog = log.New(os.Stderr, "", logFlags)
if !c.GlobalIsSet("config") { if !c.GlobalIsSet("config") {
return errors.New("config flag not set") return errors.New("config flag not set")
} }

View File

@ -7,8 +7,8 @@ import (
// "bytes" // "bytes"
_ "bufio" _ "bufio"
// "strings" // "strings"
"fmt"
"io" "io"
"log"
"os" "os"
_ "time" _ "time"
) )
@ -44,7 +44,7 @@ func main() {
panic(err) panic(err)
} }
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", chunker.ChunkCount) log.Printf("Chunk Count: %d\n", chunker.ChunkCount)
case *mode == "outgoing": case *mode == "outgoing":
@ -72,7 +72,7 @@ func main() {
conn.Close() conn.Close()
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", unchunker.ChunkCount) log.Printf("Chunk Count: %d\n", unchunker.ChunkCount)
os.Exit(0) os.Exit(0)

View File

@ -115,7 +115,6 @@ func Outgoing(remote SSHTransport) (conn io.ReadWriteCloser, err error) {
Stderr: stderrBuf.Bytes(), Stderr: stderrBuf.Bytes(),
WaitErr: err, WaitErr: err,
} }
// fmt.Fprintf(os.Stderr, "ssh conn wait err: %#v\n", f.SSHCommandError.(Error))
} else { } else {
f.SSHCommandError = nil f.SSHCommandError = nil
} }