Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Enables debug for eventhandler by config and env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Martin committed May 30, 2024
1 parent f2e0f56 commit 318359e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion event-handler/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type TeleportConfig struct {
// TeleportIdentityFile is a path to Teleport identity file
TeleportIdentityFile string `help:"Teleport identity file" type:"existingfile" name:"teleport-identity" env:"FDFWD_TELEPORT_IDENTITY"`

// TeleportDebugEnabled allows for debug logging
TeleporDebugEnabled bool `help:"Configures debug logging on" name:"teleport-debug" env:"FDFWD_DEBUG"`

// TeleportRefreshEnabled will reload the identity file from disk on the
// configured interval.
TeleportRefreshEnabled bool `help:"Configures the identity file to be reloaded from disk at a configured interval." env:"FDFWD_TELEPORT_REFRESH_ENABLED"`
Expand Down Expand Up @@ -210,7 +213,7 @@ type CLI struct {
Config kong.ConfigFlag `help:"Path to TOML configuration file" optional:"true" short:"c" type:"existingfile" env:"FDFWD_CONFIG"`

// Debug is a debug logging mode flag
Debug bool `help:"Debug logging" short:"d"`
Debug bool `help:"Debug logging" short:"d" env:"FDFWD_DEBUG"`

// Version is the version print command
Version struct{} `cmd:"true" help:"Print plugin version"`
Expand Down
1 change: 1 addition & 0 deletions event-handler/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestStartCmdConfig(t *testing.T) {
TeleportIdentityFile: path.Join(wd, "testdata", "fake-file"),
TeleportRefreshEnabled: true,
TeleportRefreshInterval: 2 * time.Minute,
TeleporDebugEnabled: false,
},
IngestConfig: IngestConfig{
StorageDir: "./storage",
Expand Down
22 changes: 17 additions & 5 deletions event-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ func main() {
)

if cli.Debug {
err := logger.Setup(logger.Config{Severity: "debug", Output: "stderr"})
if err != nil {
fmt.Println(trace.DebugReport(err))
os.Exit(-1)
}
enablelogdebug()
}

switch {
Expand All @@ -82,8 +78,24 @@ func main() {
}
}

// turn on log debugging
func enablelogdebug() {
err := logger.Setup(logger.Config{Severity: "debug", Output: "stderr"})
if err != nil {
fmt.Println(trace.DebugReport(err))
os.Exit(-1)
}

}

// start spawns the main process
func start() error {

if !cli.Debug && cli.Start.TeleportConfig.TeleporDebugEnabled {
enablelogdebug()

}

app, err := NewApp(&cli.Start)
if err != nil {
return trace.Wrap(err)
Expand Down

0 comments on commit 318359e

Please sign in to comment.