aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2017-03-14 21:34:25 +0100
committerKamil Cholewiński <harry666t@gmail.com>2017-03-14 21:34:25 +0100
commit06c1efa6c13ef4bcafaf7b9a7e58b5a2e850c1bd (patch)
tree602111d6bf1822c451181eb107697baf31a259e3
parent1359cb2ef25615a29ffe4900f22f7db81dcca89a (diff)
downloadjudo-06c1efa6c13ef4bcafaf7b9a7e58b5a2e850c1bd.zip
judo-06c1efa6c13ef4bcafaf7b9a7e58b5a2e850c1bd.tar.gz
judo-06c1efa6c13ef4bcafaf7b9a7e58b5a2e850c1bd.tar.bz2
Debug logging
-rw-r--r--libjudo/logger.go15
-rw-r--r--libjudo/proc.go1
-rw-r--r--main.go6
3 files changed, 20 insertions, 2 deletions
diff --git a/libjudo/logger.go b/libjudo/logger.go
index 170d073..516c719 100644
--- a/libjudo/logger.go
+++ b/libjudo/logger.go
@@ -1,5 +1,11 @@
package libjudo
+import (
+ "log"
+ "os"
+ "sync"
+)
+
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
@@ -16,3 +22,12 @@ func (l *NilLogger) Printf(format string, v ...interface{}) {
func (l *NilLogger) Println(v ...interface{}) {
}
+
+var debugLogger Logger = &NilLogger{}
+var onceEnableDebugLogging *sync.Once = &sync.Once{}
+
+func MoreDebugLogging() {
+ onceEnableDebugLogging.Do(func() {
+ debugLogger = log.New(os.Stderr, "debug: ", 0)
+ })
+}
diff --git a/libjudo/proc.go b/libjudo/proc.go
index 121083c..04f04c2 100644
--- a/libjudo/proc.go
+++ b/libjudo/proc.go
@@ -63,6 +63,7 @@ func writeLines(w io.WriteCloser, ch <-chan string, done chan<- interface{}) {
}
func NewProc(name string, args ...string) (proc *Proc, err error) {
+ debugLogger.Println("proc:", append([]string{name}, args...))
bufsz := 0
proc = &Proc{
stdin: make(chan string, bufsz),
diff --git a/main.go b/main.go
index ac0da62..def99ac 100644
--- a/main.go
+++ b/main.go
@@ -20,7 +20,7 @@ const usage = `usage:
judo [common flags] -c command [--] ssh-targets
judo [-v | -h]
common flags:
- [-e KEY=VALUE] [-f n] [-t s]`
+ [-d] [-e KEY=VALUE] [-f n] [-t s]`
const version = "judo 0.2-dev"
@@ -28,7 +28,7 @@ func ParseArgs(args []string) (
job *libjudo.Job, names []string, msg string,
status int, err error) {
- names, opts, err := getopt.GetOpt(args, "hvs:c:t:e:", nil)
+ names, opts, err := getopt.GetOpt(args, "hvs:c:t:e:d", nil)
if err != nil {
return nil, nil, usage, 111, err
}
@@ -66,6 +66,8 @@ func ParseArgs(args []string) (
if err != nil {
return nil, nil, usage, 111, err
}
+ case "-d":
+ libjudo.MoreDebugLogging()
}
}