Skip to content

Commit

Permalink
Support providing a log level to empire
Browse files Browse the repository at this point in the history
  • Loading branch information
mwildehahn committed Jul 14, 2016
1 parent 85dc8c7 commit eb57d64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/empire/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func newRootContext(c *cli.Context) (context.Context, error) {
if err != nil {
return nil, err
}
l := newLogger()
l, err := newLogger(c)
if err != nil {
return nil, err
}

ctx := context.Background()
if r != nil {
Expand Down Expand Up @@ -367,11 +370,17 @@ func newRunRecorder(c *cli.Context) (empire.RunRecorder, error) {

// Logger ==============================

func newLogger() log15.Logger {
func newLogger(c *cli.Context) (log15.Logger, error) {
l := log15.New()
h := log15.StreamHandler(os.Stdout, log15.LogfmtFormat())
lvl := c.String(FlagLogLevel)
log.Println(fmt.Sprintf("Using log level %s", lvl))
v, err := log15.LvlFromString(c.String(FlagLogLevel))
if err != nil {
return l, err
}
h := log15.LvlFilterHandler(v, log15.StreamHandler(os.Stdout, log15.LogfmtFormat()))
l.SetHandler(log15.LazyHandler(h))
return l
return l, err
}

// Reporter ============================
Expand Down
7 changes: 7 additions & 0 deletions cmd/empire/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
FlagEventsBackend = "events.backend"
FlagRunLogsBackend = "runlogs.backend"
FlagMessagesRequired = "messages.required"
FlagLogLevel = "log.level"

FlagGithubClient = "github.client.id"
FlagGithubClientSecret = "github.client.secret"
Expand Down Expand Up @@ -334,6 +335,12 @@ var EmpireFlags = []cli.Flag{
Usage: "If true, attached runs will be shown in `emp ps` output.",
EnvVar: "EMPIRE_X_SHOW_ATTACHED",
},
cli.StringFlag{
Name: FlagLogLevel,
Value: "info",
Usage: "Specify the log level for the empire server. You can use this to enable debug logs by specifying `debug`.",
EnvVar: "EMPIRE_LOG_LEVEL",
},
}

func main() {
Expand Down

0 comments on commit eb57d64

Please sign in to comment.