Skip to content

Commit d60a9ac

Browse files
committed
Merge pull request #34 from mistifyio/MIST-581
MIST-581 Add debug logging before and after running external zfs command
2 parents cdc0f94 + 234bbd3 commit d60a9ac

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

utils.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"regexp"
99
"strconv"
1010
"strings"
11+
12+
"code.google.com/p/go-uuid/uuid"
1113
)
1214

1315
type command struct {
@@ -34,16 +36,17 @@ func (c *command) Run(arg ...string) ([][]string, error) {
3436
}
3537
cmd.Stderr = &stderr
3638

37-
debug := strings.Join([]string{cmd.Path, strings.Join(cmd.Args, " ")}, " ")
38-
if logger != nil {
39-
logger.Log(cmd.Args)
40-
}
39+
id := uuid.New()
40+
joinedArgs := strings.Join(cmd.Args, " ")
41+
42+
logger.Log([]string{"ID:" + id, "START", joinedArgs})
4143
err := cmd.Run()
44+
logger.Log([]string{"ID:" + id, "FINISH"})
4245

4346
if err != nil {
4447
return nil, &Error{
4548
Err: err,
46-
Debug: debug,
49+
Debug: strings.Join([]string{cmd.Path, joinedArgs}, " "),
4750
Stderr: stderr.String(),
4851
}
4952
}

zfs.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,20 @@ type Logger interface {
9292
Log(cmd []string)
9393
}
9494

95-
var logger Logger
95+
type defaultLogger struct{}
96+
97+
func (*defaultLogger) Log(cmd []string) {
98+
return
99+
}
100+
101+
var logger Logger = &defaultLogger{}
96102

97103
// SetLogger set a log handler to log all commands including arguments before
98104
// they are executed
99105
func SetLogger(l Logger) {
100-
logger = l
106+
if l != nil {
107+
logger = l
108+
}
101109
}
102110

103111
// zfs is a helper function to wrap typical calls to zfs.

0 commit comments

Comments
 (0)