-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathlog.go
More file actions
36 lines (29 loc) · 821 Bytes
/
log.go
File metadata and controls
36 lines (29 loc) · 821 Bytes
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
35
36
package cli
import (
"encoding/json"
gocli "gopkg.in/src-d/go-cli.v0"
log "gopkg.in/src-d/go-log.v1"
)
// LogOptions defines logging flags. It is meant to be embedded in a
// command struct. It is similar to go-cli LogOptions, but adds the application
// name field to the default logger. It also configures the standard logrus
// logger with the same default values as go-log
type LogOptions struct {
gocli.LogOptions `group:"Log Options"`
}
// Init implements the go-cli initializer interface
func (c LogOptions) Init(a *gocli.App) error {
if c.LogFields == "" {
bytes, err := json.Marshal(log.Fields{"app": a.Parser.Name})
if err != nil {
panic(err)
}
c.LogFields = string(bytes)
}
err := c.LogOptions.Init(a)
if err != nil {
return err
}
log.DefaultFactory.ApplyToLogrus()
return nil
}