Skip to content

Commit b448942

Browse files
rubiojrmuesli
authored andcommitted
Add --debug flag
In addition to adding a new --debug flag to the binary, hide some potentially sensitive information behind the debug flag, such as the events content.
1 parent d00f6f0 commit b448942

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

beehive.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
var (
4646
configFile string
4747
versionFlag bool
48+
debugFlag bool
4849
)
4950

5051
// Config contains an entire configuration set for Beehive
@@ -95,6 +96,12 @@ func main() {
9596
Value: false,
9697
Desc: "Beehive version",
9798
},
99+
{
100+
V: &debugFlag,
101+
Name: "debug",
102+
Value: false,
103+
Desc: "Turn on debugging",
104+
},
98105
})
99106

100107
// Parse command-line args for all registered bees
@@ -107,7 +114,11 @@ func main() {
107114

108115
api.Run()
109116

110-
log.SetLevel(log.InfoLevel)
117+
if debugFlag {
118+
log.SetLevel(log.DebugLevel)
119+
} else {
120+
log.SetLevel(log.InfoLevel)
121+
}
111122

112123
log.Println()
113124
log.Println("Beehive is buzzing...")

bees/actions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ func execAction(action Action, opts map[string]interface{}) bool {
101101
if (*bee).IsRunning() {
102102
(*bee).LogAction()
103103

104-
log.Println("\tExecuting action:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
104+
log.Debugln("\tExecuting action:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
105105
for _, v := range a.Options {
106-
log.Println("\t\tOptions:", v)
106+
log.Debugln("\t\tOptions:", v)
107107
}
108108

109109
(*bee).Action(a)
110110
} else {
111-
log.Println("\tNot executing action on stopped bee:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
111+
log.Debugln("\tNot executing action on stopped bee:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
112112
for _, v := range a.Options {
113-
log.Println("\t\tOptions:", v)
113+
log.Debugln("\t\tOptions:", v)
114114
}
115115
}
116116

bees/chains.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ func execChains(event *Event) {
9797
ctx.FillMap(m)
9898

9999
failed := false
100-
log.Println("Executing chain:", c.Name, "-", c.Description)
100+
log.Debugln("Executing chain:", c.Name, "-", c.Description)
101101
for _, el := range c.Filters {
102102
if execFilter(el, m) {
103-
log.Println("\t\tPassed filter!")
103+
log.Debugln("\t\tPassed filter!")
104104
} else {
105-
log.Println("\t\tDid not pass filter!")
105+
log.Debugln("\t\tDid not pass filter!")
106106
failed = true
107107
break
108108
}

bees/events.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
// Package bees is Beehive's central module system.
2222
package bees
2323

24-
import log "github.com/sirupsen/logrus"
25-
import "runtime/debug"
26-
import "fmt"
24+
import (
25+
"fmt"
26+
"runtime/debug"
27+
28+
log "github.com/sirupsen/logrus"
29+
)
2730

2831
// An Event describes an event including its parameters.
2932
type Event struct {
@@ -49,11 +52,11 @@ func handleEvents() {
4952
bee := GetBee(event.Bee)
5053
(*bee).LogEvent()
5154

52-
log.Println()
53-
log.Println("Event received:", event.Bee, "/", event.Name, "-", GetEventDescriptor(&event).Description)
55+
log.Debugln()
56+
log.Debugln("Event received:", event.Bee, "/", event.Name, "-", GetEventDescriptor(&event).Description)
5457
for _, v := range event.Options {
5558
vv := truncateString(fmt.Sprintln(v), 1000)
56-
log.Println("\tOptions:", vv)
59+
log.Debugln("\tOptions:", vv)
5760
}
5861

5962
go func() {

0 commit comments

Comments
 (0)