-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathlog.go
More file actions
34 lines (28 loc) · 1.17 KB
/
log.go
File metadata and controls
34 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cli
import (
"gopkg.in/src-d/go-log.v1"
)
// LogOptions defines logging flags. It is meant to be embedded in a
// command struct.
type LogOptions struct {
LogLevel string `long:"log-level" env:"LOG_LEVEL" default:"info" description:"Logging level (info, debug, warning or error)"`
LogFormat string `long:"log-format" env:"LOG_FORMAT" description:"log format (text or json), defaults to text on a terminal and json otherwise"`
LogFields string `long:"log-fields" env:"LOG_FIELDS" description:"default fields for the logger, specified in json"`
LogForceFormat bool `long:"log-force-format" env:"LOG_FORCE_FORMAT" description:"ignore if it is running on a terminal or not"`
Verbose bool `long:"verbose" short:"v" description:"enable verbose logging"`
}
// Init initializes the default logger factory.
func (c *LogOptions) init(app *App) error {
if c.Verbose {
c.LogLevel = "debug"
}
log.DefaultFactory = &log.LoggerFactory{
Level: c.LogLevel,
Format: c.LogFormat,
Fields: c.LogFields,
ForceFormat: c.LogForceFormat,
}
log.DefaultFactory.ApplyToLogrus()
log.DefaultLogger = log.New(log.Fields{"app": app.Name})
return nil
}