Browse Source

Add logging

Brendan Abolivier 2 years ago
parent
commit
8d175bf33b
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
100 changed files with 7443 additions and 6 deletions
  1. 6
    0
      src/config/config.go
  2. 34
    0
      src/git/git.go
  3. 16
    1
      src/grafana/client.go
  4. 30
    0
      src/logger/logger.go
  5. 3
    0
      src/puller/main.go
  6. 22
    0
      src/puller/puller.go
  7. 3
    0
      src/pusher/main.go
  8. 45
    5
      src/pusher/webhook.go
  9. 13
    0
      vendor/manifest
  10. 118
    0
      vendor/src/github.com/sirupsen/logrus/CHANGELOG.md
  11. 21
    0
      vendor/src/github.com/sirupsen/logrus/LICENSE
  12. 509
    0
      vendor/src/github.com/sirupsen/logrus/README.md
  13. 64
    0
      vendor/src/github.com/sirupsen/logrus/alt_exit.go
  14. 83
    0
      vendor/src/github.com/sirupsen/logrus/alt_exit_test.go
  15. 14
    0
      vendor/src/github.com/sirupsen/logrus/appveyor.yml
  16. 26
    0
      vendor/src/github.com/sirupsen/logrus/doc.go
  17. 279
    0
      vendor/src/github.com/sirupsen/logrus/entry.go
  18. 77
    0
      vendor/src/github.com/sirupsen/logrus/entry_test.go
  19. 69
    0
      vendor/src/github.com/sirupsen/logrus/example_basic_test.go
  20. 35
    0
      vendor/src/github.com/sirupsen/logrus/example_hook_test.go
  21. 193
    0
      vendor/src/github.com/sirupsen/logrus/exported.go
  22. 45
    0
      vendor/src/github.com/sirupsen/logrus/formatter.go
  23. 101
    0
      vendor/src/github.com/sirupsen/logrus/formatter_bench_test.go
  24. 144
    0
      vendor/src/github.com/sirupsen/logrus/hook_test.go
  25. 34
    0
      vendor/src/github.com/sirupsen/logrus/hooks.go
  26. 39
    0
      vendor/src/github.com/sirupsen/logrus/hooks/syslog/README.md
  27. 55
    0
      vendor/src/github.com/sirupsen/logrus/hooks/syslog/syslog.go
  28. 27
    0
      vendor/src/github.com/sirupsen/logrus/hooks/syslog/syslog_test.go
  29. 95
    0
      vendor/src/github.com/sirupsen/logrus/hooks/test/test.go
  30. 39
    0
      vendor/src/github.com/sirupsen/logrus/hooks/test/test_test.go
  31. 79
    0
      vendor/src/github.com/sirupsen/logrus/json_formatter.go
  32. 199
    0
      vendor/src/github.com/sirupsen/logrus/json_formatter_test.go
  33. 323
    0
      vendor/src/github.com/sirupsen/logrus/logger.go
  34. 61
    0
      vendor/src/github.com/sirupsen/logrus/logger_bench_test.go
  35. 143
    0
      vendor/src/github.com/sirupsen/logrus/logrus.go
  36. 386
    0
      vendor/src/github.com/sirupsen/logrus/logrus_test.go
  37. 10
    0
      vendor/src/github.com/sirupsen/logrus/terminal_bsd.go
  38. 11
    0
      vendor/src/github.com/sirupsen/logrus/terminal_check_appengine.go
  39. 19
    0
      vendor/src/github.com/sirupsen/logrus/terminal_check_notappengine.go
  40. 14
    0
      vendor/src/github.com/sirupsen/logrus/terminal_linux.go
  41. 178
    0
      vendor/src/github.com/sirupsen/logrus/text_formatter.go
  42. 141
    0
      vendor/src/github.com/sirupsen/logrus/text_formatter_test.go
  43. 62
    0
      vendor/src/github.com/sirupsen/logrus/writer.go
  44. 173
    0
      vendor/src/golang.org/x/sys/unix/README.md
  45. 124
    0
      vendor/src/golang.org/x/sys/unix/affinity_linux.go
  46. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_darwin_386.s
  47. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_darwin_amd64.s
  48. 30
    0
      vendor/src/golang.org/x/sys/unix/asm_darwin_arm.s
  49. 30
    0
      vendor/src/golang.org/x/sys/unix/asm_darwin_arm64.s
  50. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_dragonfly_amd64.s
  51. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_freebsd_386.s
  52. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_freebsd_amd64.s
  53. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_freebsd_arm.s
  54. 65
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_386.s
  55. 57
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_amd64.s
  56. 57
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_arm.s
  57. 52
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_arm64.s
  58. 56
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_mips64x.s
  59. 54
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_mipsx.s
  60. 56
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_ppc64x.s
  61. 56
    0
      vendor/src/golang.org/x/sys/unix/asm_linux_s390x.s
  62. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_netbsd_386.s
  63. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_netbsd_amd64.s
  64. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_netbsd_arm.s
  65. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_openbsd_386.s
  66. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_openbsd_amd64.s
  67. 29
    0
      vendor/src/golang.org/x/sys/unix/asm_openbsd_arm.s
  68. 17
    0
      vendor/src/golang.org/x/sys/unix/asm_solaris_amd64.s
  69. 35
    0
      vendor/src/golang.org/x/sys/unix/bluetooth_linux.go
  70. 195
    0
      vendor/src/golang.org/x/sys/unix/cap_freebsd.go
  71. 13
    0
      vendor/src/golang.org/x/sys/unix/constants.go
  72. 152
    0
      vendor/src/golang.org/x/sys/unix/creds_test.go
  73. 24
    0
      vendor/src/golang.org/x/sys/unix/dev_darwin.go
  74. 51
    0
      vendor/src/golang.org/x/sys/unix/dev_darwin_test.go
  75. 30
    0
      vendor/src/golang.org/x/sys/unix/dev_dragonfly.go
  76. 50
    0
      vendor/src/golang.org/x/sys/unix/dev_dragonfly_test.go
  77. 30
    0
      vendor/src/golang.org/x/sys/unix/dev_freebsd.go
  78. 42
    0
      vendor/src/golang.org/x/sys/unix/dev_linux.go
  79. 53
    0
      vendor/src/golang.org/x/sys/unix/dev_linux_test.go
  80. 29
    0
      vendor/src/golang.org/x/sys/unix/dev_netbsd.go
  81. 50
    0
      vendor/src/golang.org/x/sys/unix/dev_netbsd_test.go
  82. 29
    0
      vendor/src/golang.org/x/sys/unix/dev_openbsd.go
  83. 54
    0
      vendor/src/golang.org/x/sys/unix/dev_openbsd_test.go
  84. 51
    0
      vendor/src/golang.org/x/sys/unix/dev_solaris_test.go
  85. 102
    0
      vendor/src/golang.org/x/sys/unix/dirent.go
  86. 9
    0
      vendor/src/golang.org/x/sys/unix/endian_big.go
  87. 9
    0
      vendor/src/golang.org/x/sys/unix/endian_little.go
  88. 31
    0
      vendor/src/golang.org/x/sys/unix/env_unix.go
  89. 227
    0
      vendor/src/golang.org/x/sys/unix/errors_freebsd_386.go
  90. 227
    0
      vendor/src/golang.org/x/sys/unix/errors_freebsd_amd64.go
  91. 226
    0
      vendor/src/golang.org/x/sys/unix/errors_freebsd_arm.go
  92. 9
    0
      vendor/src/golang.org/x/sys/unix/export_test.go
  93. 22
    0
      vendor/src/golang.org/x/sys/unix/flock.go
  94. 13
    0
      vendor/src/golang.org/x/sys/unix/flock_linux_32bit.go
  95. 46
    0
      vendor/src/golang.org/x/sys/unix/gccgo.go
  96. 41
    0
      vendor/src/golang.org/x/sys/unix/gccgo_c.c
  97. 20
    0
      vendor/src/golang.org/x/sys/unix/gccgo_linux_amd64.go
  98. 51
    0
      vendor/src/golang.org/x/sys/unix/linux/Dockerfile
  99. 482
    0
      vendor/src/golang.org/x/sys/unix/linux/mkall.go
  100. 0
    0
      vendor/src/golang.org/x/sys/unix/linux/mksysnum.pl

+ 6
- 0
src/config/config.go View File

@@ -5,6 +5,8 @@ import (
5 5
 	"strings"
6 6
 
7 7
 	"gopkg.in/yaml.v2"
8
+
9
+	"github.com/sirupsen/logrus"
8 10
 )
9 11
 
10 12
 // Config is the Go representation of the configuration file. It is filled when
@@ -57,6 +59,10 @@ func Load(filename string) (cfg *Config, err error) {
57 59
 		return
58 60
 	}
59 61
 
62
+	logrus.WithFields(logrus.Fields{
63
+		"config_file": filename,
64
+	}).Info("Loading configuration")
65
+
60 66
 	cfg = new(Config)
61 67
 	err = yaml.Unmarshal(rawCfg, cfg)
62 68
 	cfg.Grafana.IgnorePrefix = strings.ToLower(cfg.Grafana.IgnorePrefix)

+ 34
- 0
src/git/git.go View File

@@ -7,6 +7,7 @@ import (
7 7
 
8 8
 	"config"
9 9
 
10
+	"github.com/sirupsen/logrus"
10 11
 	"golang.org/x/crypto/ssh"
11 12
 	gogit "gopkg.in/src-d/go-git.v4"
12 13
 	gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
@@ -34,6 +35,12 @@ func Sync(cfg config.GitSettings) (r *gogit.Repository, err error) {
34 35
 		return
35 36
 	}
36 37
 
38
+	logrus.WithFields(logrus.Fields{
39
+		"repo":       cfg.User + "@" + cfg.URL,
40
+		"clone_path": cfg.ClonePath,
41
+		"pull":       exists,
42
+	}).Info("Synchronising the Git repository with the remote")
43
+
37 44
 	// If the clone path already exists, pull from the remote, else clone it.
38 45
 	if exists {
39 46
 		r, err = pull(cfg.ClonePath, auth)
@@ -101,12 +108,22 @@ func pull(clonePath string, auth *gitssh.PublicKeys) (*gogit.Repository, error)
101 108
 	// update"
102 109
 	if err != nil {
103 110
 		if err == gogit.NoErrAlreadyUpToDate {
111
+			logrus.WithFields(logrus.Fields{
112
+				"clone_path": clonePath,
113
+				"error":      err,
114
+			}).Info("Caught specific non-error")
115
+
104 116
 			return r, nil
105 117
 		}
106 118
 
107 119
 		// go-git doesn't have an error variable for "non-fast-forward update",
108 120
 		// so this is the only way to detect it
109 121
 		if strings.HasPrefix(err.Error(), "non-fast-forward update") {
122
+			logrus.WithFields(logrus.Fields{
123
+				"clone_path": clonePath,
124
+				"error":      err,
125
+			}).Info("Caught specific non-error")
126
+
110 127
 			return r, nil
111 128
 		}
112 129
 	}
@@ -141,6 +158,11 @@ func Push(r *gogit.Repository, cfg config.GitSettings) error {
141 158
 		return err
142 159
 	}
143 160
 
161
+	logrus.WithFields(logrus.Fields{
162
+		"repo":       cfg.User + "@" + cfg.URL,
163
+		"clone_path": cfg.ClonePath,
164
+	}).Info("Pushing to the remote")
165
+
144 166
 	// Push to remote
145 167
 	err = r.Push(&gogit.PushOptions{
146 168
 		Auth: auth,
@@ -150,12 +172,24 @@ func Push(r *gogit.Repository, cfg config.GitSettings) error {
150 172
 	// update"
151 173
 	if err != nil {
152 174
 		if err == gogit.NoErrAlreadyUpToDate {
175
+			logrus.WithFields(logrus.Fields{
176
+				"repo":       cfg.User + "@" + cfg.URL,
177
+				"clone_path": cfg.ClonePath,
178
+				"error":      err,
179
+			}).Info("Caught specific non-error")
180
+
153 181
 			return nil
154 182
 		}
155 183
 
156 184
 		// go-git doesn't have an error variable for "non-fast-forward update", so
157 185
 		// this is the only way to detect it
158 186
 		if strings.HasPrefix(err.Error(), "non-fast-forward update") {
187
+			logrus.WithFields(logrus.Fields{
188
+				"repo":       cfg.User + "@" + cfg.URL,
189
+				"clone_path": cfg.ClonePath,
190
+				"error":      err,
191
+			}).Info("Caught specific non-error")
192
+
159 193
 			return nil
160 194
 		}
161 195
 	}

+ 16
- 1
src/grafana/client.go View File

@@ -6,6 +6,8 @@ import (
6 6
 	"io/ioutil"
7 7
 	"net/http"
8 8
 	"strings"
9
+
10
+	"github.com/sirupsen/logrus"
9 11
 )
10 12
 
11 13
 // Client implements a Grafana API client, and contains the instance's base URL
@@ -42,7 +44,14 @@ func NewClient(baseURL string, apiKey string) (c *Client) {
42 44
 // status code is neither 200 nor 404 an error of type httpUnkownError is
43 45
 // returned.
44 46
 func (c *Client) request(method string, endpoint string, body []byte) ([]byte, error) {
45
-	url := c.BaseURL + "/api/" + endpoint
47
+	route := "/api/" + endpoint
48
+
49
+	logrus.WithFields(logrus.Fields{
50
+		"route":  route,
51
+		"method": method,
52
+	}).Info("Querying the Grafana HTTP API")
53
+
54
+	url := c.BaseURL + route
46 55
 
47 56
 	// Create the request
48 57
 	req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
@@ -66,6 +75,12 @@ func (c *Client) request(method string, endpoint string, body []byte) ([]byte, e
66 75
 		return nil, err
67 76
 	}
68 77
 
78
+	logrus.WithFields(logrus.Fields{
79
+		"route":  route,
80
+		"method": method,
81
+		"code":   resp.StatusCode,
82
+	}).Info("The Grafana HTTP API responded")
83
+
69 84
 	// Read the response body
70 85
 	respBody, err := ioutil.ReadAll(resp.Body)
71 86
 	if err != nil {

+ 30
- 0
src/logger/logger.go View File

@@ -0,0 +1,30 @@
1
+package logger
2
+
3
+import (
4
+	"github.com/sirupsen/logrus"
5
+)
6
+
7
+// utcFormatter is a custom logrus formatter that converts the time for all
8
+// entries to UTC.
9
+type utcFormatter struct {
10
+	logrus.Formatter
11
+}
12
+
13
+// Format implements logrus.Formatter.Format().
14
+func (f utcFormatter) Format(entry *logrus.Entry) ([]byte, error) {
15
+	entry.Time = entry.Time.UTC()
16
+	return f.Formatter.Format(entry)
17
+}
18
+
19
+// LogConfig sets the format of the default logger.
20
+func LogConfig() {
21
+	logrus.SetFormatter(&utcFormatter{
22
+		&logrus.TextFormatter{
23
+			TimestampFormat:  "2006-01-02T15:04:05.000000000Z07:00",
24
+			FullTimestamp:    true,
25
+			DisableColors:    false,
26
+			DisableTimestamp: false,
27
+			DisableSorting:   false,
28
+		},
29
+	})
30
+}

+ 3
- 0
src/puller/main.go View File

@@ -5,12 +5,15 @@ import (
5 5
 
6 6
 	"config"
7 7
 	"grafana"
8
+	"logger"
8 9
 )
9 10
 
10 11
 func main() {
11 12
 	configFile := flag.String("config", "config.yaml", "Path to the configuration file")
12 13
 	flag.Parse()
13 14
 
15
+	logger.LogConfig()
16
+
14 17
 	cfg, err := config.Load(*configFile)
15 18
 	if err != nil {
16 19
 		panic(err)

+ 22
- 0
src/puller/puller.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"git"
12 12
 	"grafana"
13 13
 
14
+	"github.com/sirupsen/logrus"
14 15
 	gogit "gopkg.in/src-d/go-git.v4"
15 16
 )
16 17
 
@@ -37,6 +38,7 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
37 38
 	}
38 39
 
39 40
 	// Get URIs for all known dashboards
41
+	logrus.Info("Getting dashboard URIs")
40 42
 	uris, err := client.GetDashboardsURIs()
41 43
 	if err != nil {
42 44
 		return err
@@ -45,6 +47,7 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
45 47
 	dv := make(map[string]diffVersion)
46 48
 
47 49
 	// Load versions
50
+	logrus.Info("Getting local dashboard versions")
48 51
 	dbVersions, err := getDashboardsVersions(cfg.Git.ClonePath)
49 52
 	if err != nil {
50 53
 		return err
@@ -52,6 +55,10 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
52 55
 
53 56
 	// Iterate over the dashboards URIs
54 57
 	for _, uri := range uris {
58
+		logrus.WithFields(logrus.Fields{
59
+			"uri": uri,
60
+		}).Info("Retrieving dashboard")
61
+
55 62
 		// Retrieve the dashboard JSON
56 63
 		dashboard, err := client.GetDashboard(uri)
57 64
 		if err != nil {
@@ -61,6 +68,12 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
61 68
 		if len(cfg.Grafana.IgnorePrefix) > 0 {
62 69
 			lowerCasedName := strings.ToLower(dashboard.Name)
63 70
 			if strings.HasPrefix(lowerCasedName, cfg.Grafana.IgnorePrefix) {
71
+				logrus.WithFields(logrus.Fields{
72
+					"uri":    uri,
73
+					"name":   dashboard.Name,
74
+					"prefix": cfg.Grafana.IgnorePrefix,
75
+				}).Info("Dashboard name starts with specified prefix, skipping")
76
+
64 77
 				continue
65 78
 			}
66 79
 		}
@@ -72,6 +85,13 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
72 85
 		// changes in the repo and add the modified file to the git index.
73 86
 		version, ok := dbVersions[dashboard.Slug]
74 87
 		if !ok || dashboard.Version > version {
88
+			logrus.WithFields(logrus.Fields{
89
+				"uri":           uri,
90
+				"name":          dashboard.Name,
91
+				"local_version": version,
92
+				"new_version":   dashboard.Version,
93
+			}).Info("Grafana has a newer version, updating")
94
+
75 95
 			if err = addDashboardChangesToRepo(
76 96
 				dashboard, cfg.Git.ClonePath, w,
77 97
 			); err != nil {
@@ -96,6 +116,8 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
96 116
 
97 117
 	// Check if there's uncommited changes, and if that's the case, commit them.
98 118
 	if !status.IsClean() {
119
+		logrus.Info("Comitting changes")
120
+
99 121
 		if err = commitNewVersions(dbVersions, dv, w, cfg); err != nil {
100 122
 			return err
101 123
 		}

+ 3
- 0
src/pusher/main.go View File

@@ -5,6 +5,7 @@ import (
5 5
 
6 6
 	"config"
7 7
 	"grafana"
8
+	"logger"
8 9
 )
9 10
 
10 11
 // The Grafana API client and the config need to be global to the package since
@@ -21,6 +22,8 @@ func main() {
21 22
 	configFile := flag.String("config", "config.yaml", "Path to the configuration file")
22 23
 	flag.Parse()
23 24
 
25
+	logger.LogConfig()
26
+
24 27
 	cfg, err = config.Load(*configFile)
25 28
 	if err != nil {
26 29
 		panic(err)

+ 45
- 5
src/pusher/webhook.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"git"
10 10
 	puller "puller"
11 11
 
12
+	"github.com/sirupsen/logrus"
12 13
 	"gopkg.in/go-playground/webhooks.v3"
13 14
 	"gopkg.in/go-playground/webhooks.v3/gitlab"
14 15
 )
@@ -42,7 +43,13 @@ func HandlePush(payload interface{}, header webhooks.Header) {
42 43
 
43 44
 	// Clone or pull the repository
44 45
 	if _, err = git.Sync(cfg.Git); err != nil {
45
-		panic(err)
46
+		logrus.WithFields(logrus.Fields{
47
+			"error":      err,
48
+			"repo":       cfg.Git.User + "@" + cfg.Git.URL,
49
+			"clone_path": cfg.Git.ClonePath,
50
+		}).Error("Failed to synchronise the Git repository with the remote")
51
+
52
+		return
46 53
 	}
47 54
 
48 55
 	// Files to push are stored in a map before being pushed to the Grafana API.
@@ -56,6 +63,12 @@ func HandlePush(payload interface{}, header webhooks.Header) {
56 63
 	for _, commit := range pl.Commits {
57 64
 		// We don't want to process commits made by the puller
58 65
 		if commit.Author.Email == cfg.Git.CommitsAuthor.Email {
66
+			logrus.WithFields(logrus.Fields{
67
+				"hash":          commit.ID,
68
+				"author_email":  commit.Author.Email,
69
+				"manager_email": cfg.Git.CommitsAuthor.Email,
70
+			}).Info("Commit was made by the manager, skipping")
71
+
59 72
 			continue
60 73
 		}
61 74
 
@@ -64,10 +77,19 @@ func HandlePush(payload interface{}, header webhooks.Header) {
64 77
 		for _, addedFile := range commit.Added {
65 78
 			ignored, err := isIgnored(addedFile)
66 79
 			if err != nil {
67
-				panic(err)
80
+				logrus.WithFields(logrus.Fields{
81
+					"error":    err,
82
+					"filename": addedFile,
83
+				}).Error("Failed to check if file is to be ignored")
84
+
85
+				continue
68 86
 			}
69 87
 
70 88
 			if !ignored {
89
+				logrus.WithFields(logrus.Fields{
90
+					"filename": addedFile,
91
+				}).Info("Setting file as file to push to Grafana")
92
+
71 93
 				filesToPush[addedFile] = true
72 94
 			}
73 95
 		}
@@ -77,10 +99,19 @@ func HandlePush(payload interface{}, header webhooks.Header) {
77 99
 		for _, modifiedFile := range commit.Modified {
78 100
 			ignored, err := isIgnored(modifiedFile)
79 101
 			if err != nil {
80
-				panic(err)
102
+				logrus.WithFields(logrus.Fields{
103
+					"error":    err,
104
+					"filename": modifiedFile,
105
+				}).Error("Failed to check if file is to be ignored")
106
+
107
+				continue
81 108
 			}
82 109
 
83 110
 			if !ignored {
111
+				logrus.WithFields(logrus.Fields{
112
+					"filename": modifiedFile,
113
+				}).Info("Setting file as file to push to Grafana")
114
+
84 115
 				filesToPush[modifiedFile] = true
85 116
 			}
86 117
 		}
@@ -91,7 +122,12 @@ func HandlePush(payload interface{}, header webhooks.Header) {
91 122
 	// Push all files to the Grafana API
92 123
 	for fileToPush := range filesToPush {
93 124
 		if err = pushFile(fileToPush); err != nil {
94
-			panic(err)
125
+			logrus.WithFields(logrus.Fields{
126
+				"error":    err,
127
+				"filename": fileToPush,
128
+			}).Error("Failed push the file to Grafana")
129
+
130
+			continue
95 131
 		}
96 132
 	}
97 133
 
@@ -99,7 +135,11 @@ func HandlePush(payload interface{}, header webhooks.Header) {
99 135
 	// dashboards, so we use the puller mechanic to pull the updated numbers and
100 136
 	// commit them in the git repo.
101 137
 	if err = puller.PullGrafanaAndCommit(grafanaClient, cfg); err != nil {
102
-		panic(err)
138
+		logrus.WithFields(logrus.Fields{
139
+			"error":      err,
140
+			"repo":       cfg.Git.User + "@" + cfg.Git.URL,
141
+			"clone_path": cfg.Git.ClonePath,
142
+		}).Error("Call to puller returned an error")
103 143
 	}
104 144
 }
105 145
 

+ 13
- 0
vendor/manifest View File

@@ -34,6 +34,12 @@
34 34
 			"path": "/diffmatchpatch"
35 35
 		},
36 36
 		{
37
+			"importpath": "github.com/sirupsen/logrus",
38
+			"repository": "https://github.com/sirupsen/logrus",
39
+			"revision": "d682213848ed68c0a260ca37d6dd5ace8423f5ba",
40
+			"branch": "master"
41
+		},
42
+		{
37 43
 			"importpath": "github.com/src-d/gcfg",
38 44
 			"repository": "https://github.com/src-d/gcfg",
39 45
 			"revision": "f187355171c936ac84a82793659ebb4936bc1c23",
@@ -80,6 +86,13 @@
80 86
 			"path": "/context"
81 87
 		},
82 88
 		{
89
+			"importpath": "golang.org/x/sys/unix",
90
+			"repository": "https://go.googlesource.com/sys",
91
+			"revision": "1792d66dc88e503d3cb2400578221cdf1f7fe26f",
92
+			"branch": "master",
93
+			"path": "/unix"
94
+		},
95
+		{
83 96
 			"importpath": "golang.org/x/text/transform",
84 97
 			"repository": "https://go.googlesource.com/text",
85 98
 			"revision": "e19ae1496984b1c655b8044a65c0300a3c878dd3",

+ 118
- 0
vendor/src/github.com/sirupsen/logrus/CHANGELOG.md View File

@@ -0,0 +1,118 @@
1
+# 1.0.4
2
+
3
+* Fix race when adding hooks (#612)
4
+* Fix terminal check in AppEngine (#635)
5
+
6
+# 1.0.3
7
+
8
+* Replace example files with testable examples
9
+
10
+# 1.0.2
11
+
12
+* bug: quote non-string values in text formatter (#583)
13
+* Make (*Logger) SetLevel a public method
14
+
15
+# 1.0.1
16
+
17
+* bug: fix escaping in text formatter (#575)
18
+
19
+# 1.0.0
20
+
21
+* Officially changed name to lower-case
22
+* bug: colors on Windows 10 (#541)
23
+* bug: fix race in accessing level (#512)
24
+
25
+# 0.11.5
26
+
27
+* feature: add writer and writerlevel to entry (#372)
28
+
29
+# 0.11.4
30
+
31
+* bug: fix undefined variable on solaris (#493)
32
+
33
+# 0.11.3
34
+
35
+* formatter: configure quoting of empty values (#484)
36
+* formatter: configure quoting character (default is `"`) (#484)
37
+* bug: fix not importing io correctly in non-linux environments (#481)
38
+
39
+# 0.11.2
40
+
41
+* bug: fix windows terminal detection (#476)
42
+
43
+# 0.11.1
44
+
45
+* bug: fix tty detection with custom out (#471)
46
+
47
+# 0.11.0
48
+
49
+* performance: Use bufferpool to allocate (#370)
50
+* terminal: terminal detection for app-engine (#343)
51
+* feature: exit handler (#375)
52
+
53
+# 0.10.0
54
+
55
+* feature: Add a test hook (#180)
56
+* feature: `ParseLevel` is now case-insensitive (#326)
57
+* feature: `FieldLogger` interface that generalizes `Logger` and `Entry` (#308)
58
+* performance: avoid re-allocations on `WithFields` (#335)
59
+
60
+# 0.9.0
61
+
62
+* logrus/text_formatter: don't emit empty msg
63
+* logrus/hooks/airbrake: move out of main repository
64
+* logrus/hooks/sentry: move out of main repository
65
+* logrus/hooks/papertrail: move out of main repository
66
+* logrus/hooks/bugsnag: move out of main repository
67
+* logrus/core: run tests with `-race`
68
+* logrus/core: detect TTY based on `stderr`
69
+* logrus/core: support `WithError` on logger
70
+* logrus/core: Solaris support
71
+
72
+# 0.8.7
73
+
74
+* logrus/core: fix possible race (#216)
75
+* logrus/doc: small typo fixes and doc improvements
76
+
77
+
78
+# 0.8.6
79
+
80
+* hooks/raven: allow passing an initialized client
81
+
82
+# 0.8.5
83
+
84
+* logrus/core: revert #208
85
+
86
+# 0.8.4
87
+
88
+* formatter/text: fix data race (#218)
89
+
90
+# 0.8.3
91
+
92
+* logrus/core: fix entry log level (#208)
93
+* logrus/core: improve performance of text formatter by 40%
94
+* logrus/core: expose `LevelHooks` type
95
+* logrus/core: add support for DragonflyBSD and NetBSD
96
+* formatter/text: print structs more verbosely
97
+
98
+# 0.8.2
99
+
100
+* logrus: fix more Fatal family functions
101
+
102
+# 0.8.1
103
+
104
+* logrus: fix not exiting on `Fatalf` and `Fatalln`
105
+
106
+# 0.8.0
107
+
108
+* logrus: defaults to stderr instead of stdout
109
+* hooks/sentry: add special field for `*http.Request`
110
+* formatter/text: ignore Windows for colors
111
+
112
+# 0.7.3
113
+
114
+* formatter/\*: allow configuration of timestamp layout
115
+
116
+# 0.7.2
117
+
118
+* formatter/text: Add configuration option for time format (#158)

+ 21
- 0
vendor/src/github.com/sirupsen/logrus/LICENSE View File

@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2014 Simon Eskildsen
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in
13
+all copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+THE SOFTWARE.

+ 509
- 0
vendor/src/github.com/sirupsen/logrus/README.md View File

@@ -0,0 +1,509 @@
1
+# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>&nbsp;[![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus)&nbsp;[![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus)
2
+
3
+Logrus is a structured logger for Go (golang), completely API compatible with
4
+the standard library logger.
5
+
6
+**Seeing weird case-sensitive problems?** It's in the past been possible to
7
+import Logrus as both upper- and lower-case. Due to the Go package environment,
8
+this caused issues in the community and we needed a standard. Some environments
9
+experienced problems with the upper-case variant, so the lower-case was decided.
10
+Everything using `logrus` will need to use the lower-case:
11
+`github.com/sirupsen/logrus`. Any package that isn't, should be changed.
12
+
13
+To fix Glide, see [these
14
+comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437).
15
+For an in-depth explanation of the casing issue, see [this
16
+comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276).
17
+
18
+**Are you interested in assisting in maintaining Logrus?** Currently I have a
19
+lot of obligations, and I am unable to provide Logrus with the maintainership it
20
+needs. If you'd like to help, please reach out to me at `simon at author's
21
+username dot com`.
22
+
23
+Nicely color-coded in development (when a TTY is attached, otherwise just
24
+plain text):
25
+
26
+![Colored](http://i.imgur.com/PY7qMwd.png)
27
+
28
+With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash
29
+or Splunk:
30
+
31
+```json
32
+{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the
33
+ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}
34
+
35
+{"level":"warning","msg":"The group's number increased tremendously!",
36
+"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"}
37
+
38
+{"animal":"walrus","level":"info","msg":"A giant walrus appears!",
39
+"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"}
40
+
41
+{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.",
42
+"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"}
43
+
44
+{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true,
45
+"time":"2014-03-10 19:57:38.562543128 -0400 EDT"}
46
+```
47
+
48
+With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not
49
+attached, the output is compatible with the
50
+[logfmt](http://godoc.org/github.com/kr/logfmt) format:
51
+
52
+```text
53
+time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
54
+time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
55
+time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
56
+time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
57
+time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
58
+time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true
59
+exit status 1
60
+```
61
+
62
+#### Case-sensitivity
63
+
64
+The organization's name was changed to lower-case--and this will not be changed
65
+back. If you are getting import conflicts due to case sensitivity, please use
66
+the lower-case import: `github.com/sirupsen/logrus`.
67
+
68
+#### Example
69
+
70
+The simplest way to use Logrus is simply the package-level exported logger:
71
+
72
+```go
73
+package main
74
+
75
+import (
76
+  log "github.com/sirupsen/logrus"
77
+)
78
+
79
+func main() {
80
+  log.WithFields(log.Fields{
81
+    "animal": "walrus",
82
+  }).Info("A walrus appears")
83
+}
84
+```
85
+
86
+Note that it's completely api-compatible with the stdlib logger, so you can
87
+replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"`
88
+and you'll now have the flexibility of Logrus. You can customize it all you
89
+want:
90
+
91
+```go
92
+package main
93
+
94
+import (
95
+  "os"
96
+  log "github.com/sirupsen/logrus"
97
+)
98
+
99
+func init() {
100
+  // Log as JSON instead of the default ASCII formatter.
101
+  log.SetFormatter(&log.JSONFormatter{})
102
+
103
+  // Output to stdout instead of the default stderr
104
+  // Can be any io.Writer, see below for File example
105
+  log.SetOutput(os.Stdout)
106
+
107
+  // Only log the warning severity or above.
108
+  log.SetLevel(log.WarnLevel)
109
+}
110
+
111
+func main() {
112
+  log.WithFields(log.Fields{
113
+    "animal": "walrus",
114
+    "size":   10,
115
+  }).Info("A group of walrus emerges from the ocean")
116
+
117
+  log.WithFields(log.Fields{
118
+    "omg":    true,
119
+    "number": 122,
120
+  }).Warn("The group's number increased tremendously!")
121
+
122
+  log.WithFields(log.Fields{
123
+    "omg":    true,
124
+    "number": 100,
125
+  }).Fatal("The ice breaks!")
126
+
127
+  // A common pattern is to re-use fields between logging statements by re-using
128
+  // the logrus.Entry returned from WithFields()
129
+  contextLogger := log.WithFields(log.Fields{
130
+    "common": "this is a common field",
131
+    "other": "I also should be logged always",
132
+  })
133
+
134
+  contextLogger.Info("I'll be logged with common and other field")
135
+  contextLogger.Info("Me too")
136
+}
137
+```
138
+
139
+For more advanced usage such as logging to multiple locations from the same
140
+application, you can also create an instance of the `logrus` Logger:
141
+
142
+```go
143
+package main
144
+
145
+import (
146
+  "os"
147
+  "github.com/sirupsen/logrus"
148
+)
149
+
150
+// Create a new instance of the logger. You can have any number of instances.
151
+var log = logrus.New()
152
+
153
+func main() {
154
+  // The API for setting attributes is a little different than the package level
155
+  // exported logger. See Godoc.
156
+  log.Out = os.Stdout
157
+
158
+  // You could set this to any `io.Writer` such as a file
159
+  // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
160
+  // if err == nil {
161
+  //  log.Out = file
162
+  // } else {
163
+  //  log.Info("Failed to log to file, using default stderr")
164
+  // }
165
+
166
+  log.WithFields(logrus.Fields{
167
+    "animal": "walrus",
168
+    "size":   10,
169
+  }).Info("A group of walrus emerges from the ocean")
170
+}
171
+```
172
+
173
+#### Fields
174
+
175
+Logrus encourages careful, structured logging through logging fields instead of
176
+long, unparseable error messages. For example, instead of: `log.Fatalf("Failed
177
+to send event %s to topic %s with key %d")`, you should log the much more
178
+discoverable:
179
+
180
+```go
181
+log.WithFields(log.Fields{
182
+  "event": event,
183
+  "topic": topic,
184
+  "key": key,
185
+}).Fatal("Failed to send event")
186
+```
187
+
188
+We've found this API forces you to think about logging in a way that produces
189
+much more useful logging messages. We've been in countless situations where just
190
+a single added field to a log statement that was already there would've saved us
191
+hours. The `WithFields` call is optional.
192
+
193
+In general, with Logrus using any of the `printf`-family functions should be
194
+seen as a hint you should add a field, however, you can still use the
195
+`printf`-family functions with Logrus.
196
+
197
+#### Default Fields
198
+
199
+Often it's helpful to have fields _always_ attached to log statements in an
200
+application or parts of one. For example, you may want to always log the
201
+`request_id` and `user_ip` in the context of a request. Instead of writing
202
+`log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on
203
+every line, you can create a `logrus.Entry` to pass around instead:
204
+
205
+```go
206
+requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})
207
+requestLogger.Info("something happened on that request") # will log request_id and user_ip
208
+requestLogger.Warn("something not great happened")
209
+```
210
+
211
+#### Hooks
212
+
213
+You can add hooks for logging levels. For example to send errors to an exception
214
+tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to
215
+multiple places simultaneously, e.g. syslog.
216
+
217
+Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in
218
+`init`:
219
+
220
+```go
221
+import (
222
+  log "github.com/sirupsen/logrus"
223
+  "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake"
224
+  logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
225
+  "log/syslog"
226
+)
227
+
228
+func init() {
229
+
230
+  // Use the Airbrake hook to report errors that have Error severity or above to
231
+  // an exception tracker. You can create custom hooks, see the Hooks section.
232
+  log.AddHook(airbrake.NewHook(123, "xyz", "production"))
233
+
234
+  hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
235
+  if err != nil {
236
+    log.Error("Unable to connect to local syslog daemon")
237
+  } else {
238
+    log.AddHook(hook)
239
+  }
240
+}
241
+```
242
+Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md).
243
+
244
+| Hook  | Description |
245
+| ----- | ----------- |
246
+| [Airbrake "legacy"](https://github.com/gemnasium/logrus-airbrake-legacy-hook) | Send errors to an exception tracking service compatible with the Airbrake API V2. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. |
247
+| [Airbrake](https://github.com/gemnasium/logrus-airbrake-hook) | Send errors to the Airbrake API V3. Uses the official [`gobrake`](https://github.com/airbrake/gobrake) behind the scenes. |
248
+| [Amazon Kinesis](https://github.com/evalphobia/logrus_kinesis) | Hook for logging to [Amazon Kinesis](https://aws.amazon.com/kinesis/) |
249
+| [Amqp-Hook](https://github.com/vladoatanasov/logrus_amqp) | Hook for logging to Amqp broker (Like RabbitMQ) |
250
+| [AzureTableHook](https://github.com/kpfaulkner/azuretablehook/) | Hook for logging to Azure Table Storage|
251
+| [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. |
252
+| [DeferPanic](https://github.com/deferpanic/dp-logrus) | Hook for logging to DeferPanic |
253
+| [Discordrus](https://github.com/kz/discordrus) | Hook for logging to [Discord](https://discordapp.com/) |
254
+| [ElasticSearch](https://github.com/sohlich/elogrus) | Hook for logging to ElasticSearch|
255
+| [Firehose](https://github.com/beaubrewer/logrus_firehose) | Hook for logging to [Amazon Firehose](https://aws.amazon.com/kinesis/firehose/)
256
+| [Fluentd](https://github.com/evalphobia/logrus_fluent) | Hook for logging to fluentd |
257
+| [Go-Slack](https://github.com/multiplay/go-slack) | Hook for logging to [Slack](https://slack.com) |
258
+| [Graylog](https://github.com/gemnasium/logrus-graylog-hook) | Hook for logging to [Graylog](http://graylog2.org/) |
259
+| [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. |
260
+| [Honeybadger](https://github.com/agonzalezro/logrus_honeybadger) | Hook for sending exceptions to Honeybadger |
261
+| [InfluxDB](https://github.com/Abramovic/logrus_influxdb) | Hook for logging to influxdb |
262
+| [Influxus](http://github.com/vlad-doru/influxus) | Hook for concurrently logging to [InfluxDB](http://influxdata.com/) |
263
+| [Journalhook](https://github.com/wercker/journalhook) | Hook for logging to `systemd-journald` |
264
+| [KafkaLogrus](https://github.com/tracer0tong/kafkalogrus) | Hook for logging to Kafka |
265
+| [LFShook](https://github.com/rifflock/lfshook) | Hook for logging to the local filesystem |
266
+| [Logbeat](https://github.com/macandmia/logbeat) | Hook for logging to [Opbeat](https://opbeat.com/) |
267
+| [Logentries](https://github.com/jcftang/logentriesrus) | Hook for logging to [Logentries](https://logentries.com/) |
268
+| [Logentrus](https://github.com/puddingfactory/logentrus) | Hook for logging to [Logentries](https://logentries.com/) |
269
+| [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) |
270
+| [Logrusly](https://github.com/sebest/logrusly) | Send logs to [Loggly](https://www.loggly.com/) |
271
+| [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) |
272
+| [Mail](https://github.com/zbindenren/logrus_mail) | Hook for sending exceptions via mail |
273
+| [Mattermost](https://github.com/shuLhan/mattermost-integration/tree/master/hooks/logrus) | Hook for logging to [Mattermost](https://mattermost.com/) |
274
+| [Mongodb](https://github.com/weekface/mgorus) | Hook for logging to mongodb |
275
+| [NATS-Hook](https://github.com/rybit/nats_logrus_hook) | Hook for logging to [NATS](https://nats.io) |
276
+| [Octokit](https://github.com/dorajistyle/logrus-octokit-hook) | Hook for logging to github via octokit |
277
+| [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. |
278
+| [PostgreSQL](https://github.com/gemnasium/logrus-postgresql-hook) | Send logs to [PostgreSQL](http://postgresql.org) |
279
+| [Promrus](https://github.com/weaveworks/promrus) | Expose number of log messages as [Prometheus](https://prometheus.io/) metrics |
280
+| [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) |
281
+| [Raygun](https://github.com/squirkle/logrus-raygun-hook) | Hook for logging to [Raygun.io](http://raygun.io/) |
282
+| [Redis-Hook](https://github.com/rogierlommers/logrus-redis-hook) | Hook for logging to a ELK stack (through Redis) |
283
+| [Rollrus](https://github.com/heroku/rollrus) | Hook for sending errors to rollbar |
284
+| [Scribe](https://github.com/sagar8192/logrus-scribe-hook) | Hook for logging to [Scribe](https://github.com/facebookarchive/scribe)|
285
+| [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. |
286
+| [Slackrus](https://github.com/johntdyer/slackrus) | Hook for Slack chat. |
287
+| [Stackdriver](https://github.com/knq/sdhook) | Hook for logging to [Google Stackdriver](https://cloud.google.com/logging/) |
288
+| [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)|
289
+| [Syslog](https://github.com/sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. |
290
+| [Syslog TLS](https://github.com/shinji62/logrus-syslog-ng) | Send errors to remote syslog server with TLS support. |
291
+| [Telegram](https://github.com/rossmcdonald/telegram_hook) | Hook for logging errors to [Telegram](https://telegram.org/) |
292
+| [TraceView](https://github.com/evalphobia/logrus_appneta) | Hook for logging to [AppNeta TraceView](https://www.appneta.com/products/traceview/) |
293
+| [Typetalk](https://github.com/dragon3/logrus-typetalk-hook) | Hook for logging to [Typetalk](https://www.typetalk.in/) |
294
+| [logz.io](https://github.com/ripcurld00d/logrus-logzio-hook) | Hook for logging to [logz.io](https://logz.io), a Log as a Service using Logstash |
295
+| [SQS-Hook](https://github.com/tsarpaul/logrus_sqs) | Hook for logging to [Amazon Simple Queue Service (SQS)](https://aws.amazon.com/sqs/) |
296
+
297
+#### Level logging
298
+
299
+Logrus has six logging levels: Debug, Info, Warning, Error, Fatal and Panic.
300
+
301
+```go
302
+log.Debug("Useful debugging information.")
303
+log.Info("Something noteworthy happened!")
304
+log.Warn("You should probably take a look at this.")
305
+log.Error("Something failed but I'm not quitting.")
306
+// Calls os.Exit(1) after logging
307
+log.Fatal("Bye.")
308
+// Calls panic() after logging
309
+log.Panic("I'm bailing.")
310
+```
311
+
312
+You can set the logging level on a `Logger`, then it will only log entries with
313
+that severity or anything above it:
314
+
315
+```go
316
+// Will log anything that is info or above (warn, error, fatal, panic). Default.
317
+log.SetLevel(log.InfoLevel)
318
+```
319
+
320
+It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose
321
+environment if your application has that.
322
+
323
+#### Entries
324
+
325
+Besides the fields added with `WithField` or `WithFields` some fields are
326
+automatically added to all logging events:
327
+
328
+1. `time`. The timestamp when the entry was created.
329
+2. `msg`. The logging message passed to `{Info,Warn,Error,Fatal,Panic}` after
330
+   the `AddFields` call. E.g. `Failed to send event.`
331
+3. `level`. The logging level. E.g. `info`.
332
+
333
+#### Environments
334
+
335
+Logrus has no notion of environment.
336
+
337
+If you wish for hooks and formatters to only be used in specific environments,
338
+you should handle that yourself. For example, if your application has a global
339
+variable `Environment`, which is a string representation of the environment you
340
+could do:
341
+
342
+```go
343
+import (
344
+  log "github.com/sirupsen/logrus"
345
+)
346
+
347
+init() {
348
+  // do something here to set environment depending on an environment variable
349
+  // or command-line flag
350
+  if Environment == "production" {
351
+    log.SetFormatter(&log.JSONFormatter{})
352
+  } else {
353
+    // The TextFormatter is default, you don't actually have to do this.
354
+    log.SetFormatter(&log.TextFormatter{})
355
+  }
356
+}
357
+```
358
+
359
+This configuration is how `logrus` was intended to be used, but JSON in
360
+production is mostly only useful if you do log aggregation with tools like
361
+Splunk or Logstash.
362
+
363
+#### Formatters
364
+
365
+The built-in logging formatters are:
366
+
367
+* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise
368
+  without colors.
369
+  * *Note:* to force colored output when there is no TTY, set the `ForceColors`
370
+    field to `true`.  To force no colored output even if there is a TTY  set the
371
+    `DisableColors` field to `true`. For Windows, see
372
+    [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable).
373
+  * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter).
374
+* `logrus.JSONFormatter`. Logs fields as JSON.
375
+  * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter).
376
+
377
+Third party logging formatters:
378
+
379
+* [`FluentdFormatter`](https://github.com/joonix/log). Formats entries that can be parsed by Kubernetes and Google Container Engine.
380
+* [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events.
381
+* [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout.
382
+* [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.
383
+
384
+You can define your formatter by implementing the `Formatter` interface,
385
+requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a
386
+`Fields` type (`map[string]interface{}`) with all your fields as well as the
387
+default ones (see Entries section above):
388
+
389
+```go
390
+type MyJSONFormatter struct {
391
+}
392
+
393
+log.SetFormatter(new(MyJSONFormatter))
394
+
395
+func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) {
396
+  // Note this doesn't include Time, Level and Message which are available on
397
+  // the Entry. Consult `godoc` on information about those fields or read the
398
+  // source of the official loggers.
399
+  serialized, err := json.Marshal(entry.Data)
400
+    if err != nil {
401
+      return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
402
+    }
403
+  return append(serialized, '\n'), nil
404
+}
405
+```
406
+
407
+#### Logger as an `io.Writer`
408
+
409
+Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it.
410
+
411
+```go
412
+w := logger.Writer()
413
+defer w.Close()
414
+
415
+srv := http.Server{
416
+    // create a stdlib log.Logger that writes to
417
+    // logrus.Logger.
418
+    ErrorLog: log.New(w, "", 0),
419
+}
420
+```
421
+
422
+Each line written to that writer will be printed the usual way, using formatters
423
+and hooks. The level for those entries is `info`.
424
+
425
+This means that we can override the standard library logger easily:
426
+
427
+```go
428
+logger := logrus.New()
429
+logger.Formatter = &logrus.JSONFormatter{}
430
+
431
+// Use logrus for standard log output
432
+// Note that `log` here references stdlib's log
433
+// Not logrus imported under the name `log`.
434
+log.SetOutput(logger.Writer())
435
+```
436
+
437
+#### Rotation
438
+
439
+Log rotation is not provided with Logrus. Log rotation should be done by an
440
+external program (like `logrotate(8)`) that can compress and delete old log
441
+entries. It should not be a feature of the application-level logger.
442
+
443
+#### Tools
444
+
445
+| Tool | Description |
446
+| ---- | ----------- |
447
+|[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.|
448
+|[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) |
449
+
450
+#### Testing
451
+
452
+Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides:
453
+
454
+* decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just add the `test` hook
455
+* a test logger (`test.NewNullLogger`) that just records log messages (and does not output any):
456
+
457
+```go
458
+import(
459
+  "github.com/sirupsen/logrus"
460
+  "github.com/sirupsen/logrus/hooks/test"
461
+  "github.com/stretchr/testify/assert"
462
+  "testing"
463
+)
464
+
465
+func TestSomething(t*testing.T){
466
+  logger, hook := test.NewNullLogger()
467
+  logger.Error("Helloerror")
468
+
469
+  assert.Equal(t, 1, len(hook.Entries))
470
+  assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level)
471
+  assert.Equal(t, "Helloerror", hook.LastEntry().Message)
472
+
473
+  hook.Reset()
474
+  assert.Nil(t, hook.LastEntry())
475
+}
476
+```
477
+
478
+#### Fatal handlers
479
+
480
+Logrus can register one or more functions that will be called when any `fatal`
481
+level message is logged. The registered handlers will be executed before
482
+logrus performs a `os.Exit(1)`. This behavior may be helpful if callers need
483
+to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted.
484
+
485
+```
486
+...
487
+handler := func() {
488
+  // gracefully shutdown something...
489
+}
490
+logrus.RegisterExitHandler(handler)
491
+...
492
+```
493
+
494
+#### Thread safety
495
+
496
+By default Logger is protected by mutex for concurrent writes, this mutex is invoked when calling hooks and writing logs.
497
+If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking.
498
+
499
+Situation when locking is not needed includes:
500
+
501
+* You have no hooks registered, or hooks calling is already thread-safe.
502
+
503
+* Writing to logger.Out is already thread-safe, for example:
504
+
505
+  1) logger.Out is protected by locks.
506
+
507
+  2) logger.Out is a os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allow multi-thread/multi-process writing)
508
+
509
+     (Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/)

+ 64
- 0
vendor/src/github.com/sirupsen/logrus/alt_exit.go View File

@@ -0,0 +1,64 @@
1
+package logrus
2
+
3
+// The following code was sourced and modified from the
4
+// https://github.com/tebeka/atexit package governed by the following license:
5
+//
6
+// Copyright (c) 2012 Miki Tebeka <miki.tebeka@gmail.com>.
7
+//
8
+// Permission is hereby granted, free of charge, to any person obtaining a copy of
9
+// this software and associated documentation files (the "Software"), to deal in
10
+// the Software without restriction, including without limitation the rights to
11
+// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12
+// the Software, and to permit persons to whom the Software is furnished to do so,
13
+// subject to the following conditions:
14
+//
15
+// The above copyright notice and this permission notice shall be included in all
16
+// copies or substantial portions of the Software.
17
+//
18
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20
+// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21
+// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22
+// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+import (
26
+	"fmt"
27
+	"os"
28
+)
29
+
30
+var handlers = []func(){}
31
+
32
+func runHandler(handler func()) {
33
+	defer func() {
34
+		if err := recover(); err != nil {
35
+			fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err)
36
+		}
37
+	}()
38
+
39
+	handler()
40
+}
41
+
42
+func runHandlers() {
43
+	for _, handler := range handlers {
44
+		runHandler(handler)
45
+	}
46
+}
47
+
48
+// Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)
49
+func Exit(code int) {
50
+	runHandlers()
51
+	os.Exit(code)
52
+}
53
+
54
+// RegisterExitHandler adds a Logrus Exit handler, call logrus.Exit to invoke
55
+// all handlers. The handlers will also be invoked when any Fatal log entry is
56
+// made.
57
+//
58
+// This method is useful when a caller wishes to use logrus to log a fatal
59
+// message but also needs to gracefully shutdown. An example usecase could be
60
+// closing database connections, or sending a alert that the application is
61
+// closing.
62
+func RegisterExitHandler(handler func()) {
63
+	handlers = append(handlers, handler)
64
+}

+ 83
- 0
vendor/src/github.com/sirupsen/logrus/alt_exit_test.go View File

@@ -0,0 +1,83 @@
1
+package logrus
2
+
3
+import (
4
+	"io/ioutil"
5
+	"log"
6
+	"os"
7
+	"os/exec"
8
+	"path/filepath"
9
+	"testing"
10
+	"time"
11
+)
12
+
13
+func TestRegister(t *testing.T) {
14
+	current := len(handlers)
15
+	RegisterExitHandler(func() {})
16
+	if len(handlers) != current+1 {
17
+		t.Fatalf("expected %d handlers, got %d", current+1, len(handlers))
18
+	}
19
+}
20
+
21
+func TestHandler(t *testing.T) {
22
+	tempDir, err := ioutil.TempDir("", "test_handler")
23
+	if err != nil {
24
+		log.Fatalf("can't create temp dir. %q", err)
25
+	}
26
+	defer os.RemoveAll(tempDir)
27
+
28
+	gofile := filepath.Join(tempDir, "gofile.go")
29
+	if err := ioutil.WriteFile(gofile, testprog, 0666); err != nil {
30
+		t.Fatalf("can't create go file. %q", err)
31
+	}
32
+
33
+	outfile := filepath.Join(tempDir, "outfile.out")
34
+	arg := time.Now().UTC().String()
35
+	err = exec.Command("go", "run", gofile, outfile, arg).Run()
36
+	if err == nil {
37
+		t.Fatalf("completed normally, should have failed")
38
+	}
39
+
40
+	data, err := ioutil.ReadFile(outfile)
41
+	if err != nil {
42
+		t.Fatalf("can't read output file %s. %q", outfile, err)
43
+	}
44
+
45
+	if string(data) != arg {
46
+		t.Fatalf("bad data. Expected %q, got %q", data, arg)
47
+	}
48
+}
49
+
50
+var testprog = []byte(`
51
+// Test program for atexit, gets output file and data as arguments and writes
52
+// data to output file in atexit handler.
53
+package main
54
+
55
+import (
56
+	"github.com/sirupsen/logrus"
57
+	"flag"
58
+	"fmt"
59
+	"io/ioutil"
60
+)
61
+
62
+var outfile = ""
63
+var data = ""
64
+
65
+func handler() {
66
+	ioutil.WriteFile(outfile, []byte(data), 0666)
67
+}
68
+
69
+func badHandler() {
70
+	n := 0
71
+	fmt.Println(1/n)
72
+}
73
+
74
+func main() {
75
+	flag.Parse()
76
+	outfile = flag.Arg(0)
77
+	data = flag.Arg(1)
78
+
79
+	logrus.RegisterExitHandler(handler)
80
+	logrus.RegisterExitHandler(badHandler)
81
+	logrus.Fatal("Bye bye")
82
+}
83
+`)

+ 14
- 0
vendor/src/github.com/sirupsen/logrus/appveyor.yml View File

@@ -0,0 +1,14 @@
1
+version: "{build}"
2
+platform: x64
3
+clone_folder: c:\gopath\src\github.com\sirupsen\logrus
4
+environment:  
5
+  GOPATH: c:\gopath
6
+branches:  
7
+  only:
8
+    - master
9
+install:  
10
+  - set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
11
+  - go version
12
+build_script:  
13
+  - go get -t
14
+  - go test

+ 26
- 0
vendor/src/github.com/sirupsen/logrus/doc.go View File

@@ -0,0 +1,26 @@
1
+/*
2
+Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
3
+
4
+
5
+The simplest way to use Logrus is simply the package-level exported logger:
6
+
7
+  package main
8
+
9
+  import (
10
+    log "github.com/sirupsen/logrus"
11
+  )
12
+
13
+  func main() {
14
+    log.WithFields(log.Fields{
15
+      "animal": "walrus",
16
+      "number": 1,
17
+      "size":   10,
18
+    }).Info("A walrus appears")
19
+  }
20
+
21
+Output:
22
+  time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10
23
+
24
+For a full guide visit https://github.com/sirupsen/logrus
25
+*/
26
+package logrus

+ 279
- 0
vendor/src/github.com/sirupsen/logrus/entry.go View File

@@ -0,0 +1,279 @@
1
+package logrus
2
+
3
+import (
4
+	"bytes"
5
+	"fmt"
6
+	"os"
7
+	"sync"
8
+	"time"
9
+)
10
+
11
+var bufferPool *sync.Pool
12
+
13
+func init() {
14
+	bufferPool = &sync.Pool{
15
+		New: func() interface{} {
16
+			return new(bytes.Buffer)
17
+		},
18
+	}
19
+}
20
+
21
+// Defines the key when adding errors using WithError.
22
+var ErrorKey = "error"
23
+
24
+// An entry is the final or intermediate Logrus logging entry. It contains all
25
+// the fields passed with WithField{,s}. It's finally logged when Debug, Info,
26
+// Warn, Error, Fatal or Panic is called on it. These objects can be reused and
27
+// passed around as much as you wish to avoid field duplication.
28
+type Entry struct {
29
+	Logger *Logger
30
+
31
+	// Contains all the fields set by the user.
32
+	Data Fields
33
+
34
+	// Time at which the log entry was created
35
+	Time time.Time
36
+
37
+	// Level the log entry was logged at: Debug, Info, Warn, Error, Fatal or Panic
38
+	// This field will be set on entry firing and the value will be equal to the one in Logger struct field.
39
+	Level Level
40
+
41
+	// Message passed to Debug, Info, Warn, Error, Fatal or Panic
42
+	Message string
43
+
44
+	// When formatter is called in entry.log(), an Buffer may be set to entry
45
+	Buffer *bytes.Buffer
46
+}
47
+
48
+func NewEntry(logger *Logger) *Entry {
49
+	return &Entry{
50
+		Logger: logger,
51
+		// Default is three fields, give a little extra room
52
+		Data: make(Fields, 5),
53
+	}
54
+}
55
+
56
+// Returns the string representation from the reader and ultimately the
57
+// formatter.
58
+func (entry *Entry) String() (string, error) {
59
+	serialized, err := entry.Logger.Formatter.Format(entry)
60
+	if err != nil {
61
+		return "", err
62
+	}
63
+	str := string(serialized)
64
+	return str, nil
65
+}
66
+
67
+// Add an error as single field (using the key defined in ErrorKey) to the Entry.
68
+func (entry *Entry) WithError(err error) *Entry {
69
+	return entry.WithField(ErrorKey, err)
70
+}
71
+
72
+// Add a single field to the Entry.
73
+func (entry *Entry) WithField(key string, value interface{}) *Entry {
74
+	return entry.WithFields(Fields{key: value})
75
+}
76
+
77
+// Add a map of fields to the Entry.
78
+func (entry *Entry) WithFields(fields Fields) *Entry {
79
+	data := make(Fields, len(entry.Data)+len(fields))
80
+	for k, v := range entry.Data {
81
+		data[k] = v
82
+	}
83
+	for k, v := range fields {
84
+		data[k] = v
85
+	}
86
+	return &Entry{Logger: entry.Logger, Data: data}
87
+}
88
+
89
+// This function is not declared with a pointer value because otherwise
90
+// race conditions will occur when using multiple goroutines
91
+func (entry Entry) log(level Level, msg string) {
92
+	var buffer *bytes.Buffer
93
+	entry.Time = time.Now()
94
+	entry.Level = level
95
+	entry.Message = msg
96
+
97
+	entry.Logger.mu.Lock()
98
+	err := entry.Logger.Hooks.Fire(level, &entry)
99
+	entry.Logger.mu.Unlock()
100
+	if err != nil {
101
+		entry.Logger.mu.Lock()
102
+		fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
103
+		entry.Logger.mu.Unlock()
104
+	}
105
+	buffer = bufferPool.Get().(*bytes.Buffer)
106
+	buffer.Reset()
107
+	defer bufferPool.Put(buffer)
108
+	entry.Buffer = buffer
109
+	serialized, err := entry.Logger.Formatter.Format(&entry)
110
+	entry.Buffer = nil
111
+	if err != nil {
112
+		entry.Logger.mu.Lock()
113
+		fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
114
+		entry.Logger.mu.Unlock()
115
+	} else {
116
+		entry.Logger.mu.Lock()
117
+		_, err = entry.Logger.Out.Write(serialized)
118
+		if err != nil {
119
+			fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
120
+		}
121
+		entry.Logger.mu.Unlock()
122
+	}
123
+
124
+	// To avoid Entry#log() returning a value that only would make sense for
125
+	// panic() to use in Entry#Panic(), we avoid the allocation by checking
126
+	// directly here.
127
+	if level <= PanicLevel {
128
+		panic(&entry)
129
+	}
130
+}
131
+
132
+func (entry *Entry) Debug(args ...interface{}) {
133
+	if entry.Logger.level() >= DebugLevel {
134
+		entry.log(DebugLevel, fmt.Sprint(args...))
135
+	}
136
+}
137
+
138
+func (entry *Entry) Print(args ...interface{}) {
139
+	entry.Info(args...)
140
+}
141
+
142
+func (entry *Entry) Info(args ...interface{}) {
143
+	if entry.Logger.level() >= InfoLevel {
144
+		entry.log(InfoLevel, fmt.Sprint(args...))
145
+	}
146
+}
147
+
148
+func (entry *Entry) Warn(args ...interface{}) {
149
+	if entry.Logger.level() >= WarnLevel {
150
+		entry.log(WarnLevel, fmt.Sprint(args...))
151
+	}
152
+}
153
+
154
+func (entry *Entry) Warning(args ...interface{}) {
155
+	entry.Warn(args...)
156
+}
157
+
158
+func (entry *Entry) Error(args ...interface{}) {
159
+	if entry.Logger.level() >= ErrorLevel {
160
+		entry.log(ErrorLevel, fmt.Sprint(args...))
161
+	}
162
+}
163
+
164
+func (entry *Entry) Fatal(args ...interface{}) {
165
+	if entry.Logger.level() >= FatalLevel {
166
+		entry.log(FatalLevel, fmt.Sprint(args...))
167
+	}
168
+	Exit(1)
169
+}
170
+
171
+func (entry *Entry) Panic(args ...interface{}) {
172
+	if entry.Logger.level() >= PanicLevel {
173
+		entry.log(PanicLevel, fmt.Sprint(args...))
174
+	}
175
+	panic(fmt.Sprint(args...))
176
+}
177
+
178
+// Entry Printf family functions
179
+
180
+func (entry *Entry) Debugf(format string, args ...interface{}) {
181
+	if entry.Logger.level() >= DebugLevel {
182
+		entry.Debug(fmt.Sprintf(format, args...))
183
+	}
184
+}
185
+
186
+func (entry *Entry) Infof(format string, args ...interface{}) {
187
+	if entry.Logger.level() >= InfoLevel {
188
+		entry.Info(fmt.Sprintf(format, args...))
189
+	}
190
+}
191
+
192
+func (entry *Entry) Printf(format string, args ...interface{}) {
193
+	entry.Infof(format, args...)
194
+}
195
+
196
+func (entry *Entry) Warnf(format string, args ...interface{}) {
197
+	if entry.Logger.level() >= WarnLevel {
198
+		entry.Warn(fmt.Sprintf(format, args...))
199
+	}
200
+}
201
+
202
+func (entry *Entry) Warningf(format string, args ...interface{}) {
203
+	entry.Warnf(format, args...)
204
+}
205
+
206
+func (entry *Entry) Errorf(format string, args ...interface{}) {
207
+	if entry.Logger.level() >= ErrorLevel {
208
+		entry.Error(fmt.Sprintf(format, args...))
209
+	}
210
+}
211
+
212
+func (entry *Entry) Fatalf(format string, args ...interface{}) {
213
+	if entry.Logger.level() >= FatalLevel {
214
+		entry.Fatal(fmt.Sprintf(format, args...))
215
+	}
216
+	Exit(1)
217
+}
218
+
219
+func (entry *Entry) Panicf(format string, args ...interface{}) {
220
+	if entry.Logger.level() >= PanicLevel {
221
+		entry.Panic(fmt.Sprintf(format, args...))
222
+	}
223
+}
224
+
225
+// Entry Println family functions
226
+
227
+func (entry *Entry) Debugln(args ...interface{}) {
228
+	if entry.Logger.level() >= DebugLevel {
229
+		entry.Debug(entry.sprintlnn(args...))
230
+	}
231
+}
232
+
233
+func (entry *Entry) Infoln(args ...interface{}) {
234
+	if entry.Logger.level() >= InfoLevel {
235
+		entry.Info(entry.sprintlnn(args...))
236
+	}
237
+}
238
+
239
+func (entry *Entry) Println(args ...interface{}) {
240
+	entry.Infoln(args...)
241
+}
242
+
243
+func (entry *Entry) Warnln(args ...interface{}) {
244
+	if entry.Logger.level() >= WarnLevel {
245
+		entry.Warn(entry.sprintlnn(args...))
246
+	}
247
+}
248
+
249
+func (entry *Entry) Warningln(args ...interface{}) {
250
+	entry.Warnln(args...)
251
+}
252
+
253
+func (entry *Entry) Errorln(args ...interface{}) {
254
+	if entry.Logger.level() >= ErrorLevel {
255
+		entry.Error(entry.sprintlnn(args...))
256
+	}
257
+}
258
+
259
+func (entry *Entry) Fatalln(args ...interface{}) {
260
+	if entry.Logger.level() >= FatalLevel {
261
+		entry.Fatal(entry.sprintlnn(args...))
262
+	}
263
+	Exit(1)
264
+}
265
+
266
+func (entry *Entry) Panicln(args ...interface{}) {
267
+	if entry.Logger.level() >= PanicLevel {
268
+		entry.Panic(entry.sprintlnn(args...))
269
+	}
270
+}
271
+
272
+// Sprintlnn => Sprint no newline. This is to get the behavior of how
273
+// fmt.Sprintln where spaces are always added between operands, regardless of
274
+// their type. Instead of vendoring the Sprintln implementation to spare a
275
+// string allocation, we do the simplest thing.
276
+func (entry *Entry) sprintlnn(args ...interface{}) string {
277
+	msg := fmt.Sprintln(args...)
278
+	return msg[:len(msg)-1]
279
+}

+ 77
- 0
vendor/src/github.com/sirupsen/logrus/entry_test.go View File

@@ -0,0 +1,77 @@
1
+package logrus
2
+
3
+import (
4
+	"bytes"
5
+	"fmt"
6
+	"testing"
7
+
8
+	"github.com/stretchr/testify/assert"
9
+)
10
+
11
+func TestEntryWithError(t *testing.T) {
12
+
13
+	assert := assert.New(t)
14
+
15
+	defer func() {
16
+		ErrorKey = "error"
17
+	}()
18
+
19
+	err := fmt.Errorf("kaboom at layer %d", 4711)
20
+
21
+	assert.Equal(err, WithError(err).Data["error"])
22
+
23
+	logger := New()
24
+	logger.Out = &bytes.Buffer{}
25
+	entry := NewEntry(logger)
26
+
27
+	assert.Equal(err, entry.WithError(err).Data["error"])
28
+
29
+	ErrorKey = "err"
30
+
31
+	assert.Equal(err, entry.WithError(err).Data["err"])
32
+
33
+}
34
+
35
+func TestEntryPanicln(t *testing.T) {
36
+	errBoom := fmt.Errorf("boom time")
37
+
38
+	defer func() {
39
+		p := recover()
40
+		assert.NotNil(t, p)
41
+
42
+		switch pVal := p.(type) {
43
+		case *Entry:
44
+			assert.Equal(t, "kaboom", pVal.Message)
45
+			assert.Equal(t, errBoom, pVal.Data["err"])
46
+		default:
47
+			t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
48
+		}
49
+	}()
50
+
51
+	logger := New()
52
+	logger.Out = &bytes.Buffer{}
53
+	entry := NewEntry(logger)
54
+	entry.WithField("err", errBoom).Panicln("kaboom")
55
+}
56
+
57
+func TestEntryPanicf(t *testing.T) {
58
+	errBoom := fmt.Errorf("boom again")
59
+
60
+	defer func() {
61
+		p := recover()
62
+		assert.NotNil(t, p)
63
+
64
+		switch pVal := p.(type) {
65
+		case *Entry:
66
+			assert.Equal(t, "kaboom true", pVal.Message)
67
+			assert.Equal(t, errBoom, pVal.Data["err"])
68
+		default:
69
+			t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
70
+		}
71
+	}()
72
+
73
+	logger := New()
74
+	logger.Out = &bytes.Buffer{}
75
+	entry := NewEntry(logger)
76
+	entry.WithField("err", errBoom).Panicf("kaboom %v", true)
77
+}

+ 69
- 0
vendor/src/github.com/sirupsen/logrus/example_basic_test.go View File

@@ -0,0 +1,69 @@
1
+package logrus_test
2
+
3
+import (
4
+	"github.com/sirupsen/logrus"
5
+	"os"
6
+)
7
+
8
+func Example_basic() {
9
+	var log = logrus.New()
10
+	log.Formatter = new(logrus.JSONFormatter)
11
+	log.Formatter = new(logrus.TextFormatter)                     //default
12
+	log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
13
+	log.Level = logrus.DebugLevel
14
+	log.Out = os.Stdout
15
+
16
+	// file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
17
+	// if err == nil {
18
+	// 	log.Out = file
19
+	// } else {
20
+	// 	log.Info("Failed to log to file, using default stderr")
21
+	// }
22
+
23
+	defer func() {
24
+		err := recover()
25
+		if err != nil {
26
+			entry := err.(*logrus.Entry)
27
+			log.WithFields(logrus.Fields{
28
+				"omg":         true,
29
+				"err_animal":  entry.Data["animal"],
30
+				"err_size":    entry.Data["size"],
31
+				"err_level":   entry.Level,
32
+				"err_message": entry.Message,
33
+				"number":      100,
34
+			}).Error("The ice breaks!") // or use Fatal() to force the process to exit with a nonzero code
35
+		}
36
+	}()
37
+
38
+	log.WithFields(logrus.Fields{
39
+		"animal": "walrus",
40
+		"number": 8,
41
+	}).Debug("Started observing beach")
42
+
43
+	log.WithFields(logrus.Fields{
44
+		"animal": "walrus",
45
+		"size":   10,
46
+	}).Info("A group of walrus emerges from the ocean")
47
+
48
+	log.WithFields(logrus.Fields{
49
+		"omg":    true,
50
+		"number": 122,
51
+	}).Warn("The group's number increased tremendously!")
52
+
53
+	log.WithFields(logrus.Fields{
54
+		"temperature": -4,
55
+	}).Debug("Temperature changes")
56
+
57
+	log.WithFields(logrus.Fields{
58
+		"animal": "orca",
59
+		"size":   9009,
60
+	}).Panic("It's over 9000!")
61
+
62
+	// Output:
63
+	// level=debug msg="Started observing beach" animal=walrus number=8
64
+	// level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
65
+	// level=warning msg="The group's number increased tremendously!" number=122 omg=true
66
+	// level=debug msg="Temperature changes" temperature=-4
67
+	// level=panic msg="It's over 9000!" animal=orca size=9009
68
+	// level=error msg="The ice breaks!" err_animal=orca err_level=panic err_message="It's over 9000!" err_size=9009 number=100 omg=true
69
+}

+ 35
- 0
vendor/src/github.com/sirupsen/logrus/example_hook_test.go View File

@@ -0,0 +1,35 @@
1
+package logrus_test
2
+
3
+import (
4
+	"github.com/sirupsen/logrus"
5
+	"gopkg.in/gemnasium/logrus-airbrake-hook.v2"
6
+	"os"
7
+)
8
+
9
+func Example_hook() {
10
+	var log = logrus.New()
11
+	log.Formatter = new(logrus.TextFormatter)                     // default
12
+	log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
13
+	log.Hooks.Add(airbrake.NewHook(123, "xyz", "development"))
14
+	log.Out = os.Stdout
15
+
16
+	log.WithFields(logrus.Fields{
17
+		"animal": "walrus",
18
+		"size":   10,
19
+	}).Info("A group of walrus emerges from the ocean")
20
+
21
+	log.WithFields(logrus.Fields{
22
+		"omg":    true,
23
+		"number": 122,
24
+	}).Warn("The group's number increased tremendously!")
25
+
26
+	log.WithFields(logrus.Fields{
27
+		"omg":    true,
28
+		"number": 100,
29
+	}).Error("The ice breaks!")
30
+
31
+	// Output:
32
+	// level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
33
+	// level=warning msg="The group's number increased tremendously!" number=122 omg=true
34
+	// level=error msg="The ice breaks!" number=100 omg=true
35
+}

+ 193
- 0
vendor/src/github.com/sirupsen/logrus/exported.go View File

@@ -0,0 +1,193 @@
1
+package logrus
2
+
3
+import (
4
+	"io"
5
+)
6
+
7
+var (
8
+	// std is the name of the standard logger in stdlib `log`
9
+	std = New()
10
+)
11
+
12
+func StandardLogger() *Logger {
13
+	return std
14
+}
15
+
16
+// SetOutput sets the standard logger output.
17
+func SetOutput(out io.Writer) {
18
+	std.mu.Lock()
19
+	defer std.mu.Unlock()
20
+	std.Out = out
21
+}
22
+
23
+// SetFormatter sets the standard logger formatter.
24
+func SetFormatter(formatter Formatter) {
25
+	std.mu.Lock()
26
+	defer std.mu.Unlock()
27
+	std.Formatter = formatter
28
+}
29
+
30
+// SetLevel sets the standard logger level.
31
+func SetLevel(level Level) {
32
+	std.mu.Lock()
33
+	defer std.mu.Unlock()
34
+	std.SetLevel(level)
35
+}
36
+
37
+// GetLevel returns the standard logger level.
38
+func GetLevel() Level {
39
+	std.mu.Lock()
40
+	defer std.mu.Unlock()
41
+	return std.level()
42
+}
43
+
44
+// AddHook adds a hook to the standard logger hooks.
45
+func AddHook(hook Hook) {
46
+	std.mu.Lock()
47
+	defer std.mu.Unlock()
48
+	std.Hooks.Add(hook)
49
+}
50
+
51
+// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
52
+func WithError(err error) *Entry {
53
+	return std.WithField(ErrorKey, err)
54
+}
55
+
56
+// WithField creates an entry from the standard logger and adds a field to
57
+// it. If you want multiple fields, use `WithFields`.
58
+//
59
+// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
60
+// or Panic on the Entry it returns.
61
+func WithField(key string, value interface{}) *Entry {
62
+	return std.WithField(key, value)
63
+}
64
+
65
+// WithFields creates an entry from the standard logger and adds multiple
66
+// fields to it. This is simply a helper for `WithField`, invoking it
67
+// once for each field.
68
+//
69
+// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
70
+// or Panic on the Entry it returns.
71
+func WithFields(fields Fields) *Entry {
72
+	return std.WithFields(fields)
73
+}
74
+
75
+// Debug logs a message at level Debug on the standard logger.
76
+func Debug(args ...interface{}) {
77
+	std.Debug(args...)
78
+}
79
+
80
+// Print logs a message at level Info on the standard logger.
81
+func Print(args ...interface{}) {
82
+	std.Print(args...)
83
+}
84
+
85
+// Info logs a message at level Info on the standard logger.
86
+func Info(args ...interface{}) {
87
+	std.Info(args...)
88
+}
89
+
90
+// Warn logs a message at level Warn on the standard logger.
91
+func Warn(args ...interface{}) {
92
+	std.Warn(args...)
93
+}
94
+
95
+// Warning logs a message at level Warn on the standard logger.
96
+func Warning(args ...interface{}) {
97
+	std.Warning(args...)
98
+}
99
+
100
+// Error logs a message at level Error on the standard logger.
101
+func Error(args ...interface{}) {
102
+	std.Error(args...)
103
+}
104
+
105
+// Panic logs a message at level Panic on the standard logger.
106
+func Panic(args ...interface{}) {
107
+	std.Panic(args...)
108
+}
109
+
110
+// Fatal logs a message at level Fatal on the standard logger.
111
+func Fatal(args ...interface{}) {
112
+	std.Fatal(args...)
113
+}
114
+
115
+// Debugf logs a message at level Debug on the standard logger.
116
+func Debugf(format string, args ...interface{}) {
117
+	std.Debugf(format, args...)
118
+}
119
+
120
+// Printf logs a message at level Info on the standard logger.
121
+func Printf(format string, args ...interface{}) {
122
+	std.Printf(format, args...)
123
+}
124
+
125
+// Infof logs a message at level Info on the standard logger.
126
+func Infof(format string, args ...interface{}) {
127
+	std.Infof(format, args...)
128
+}
129
+
130
+// Warnf logs a message at level Warn on the standard logger.
131
+func Warnf(format string, args ...interface{}) {
132
+	std.Warnf(format, args...)
133
+}
134
+
135
+// Warningf logs a message at level Warn on the standard logger.
136
+func Warningf(format string, args ...interface{}) {
137
+	std.Warningf(format, args...)
138
+}
139
+
140
+// Errorf logs a message at level Error on the standard logger.
141
+func Errorf(format string, args ...interface{}) {
142
+	std.Errorf(format, args...)
143
+}
144
+
145
+// Panicf logs a message at level Panic on the standard logger.
146
+func Panicf(format string, args ...interface{}) {
147
+	std.Panicf(format, args...)
148
+}
149
+
150
+// Fatalf logs a message at level Fatal on the standard logger.
151
+func Fatalf(format string, args ...interface{}) {
152
+	std.Fatalf(format, args...)
153
+}
154
+
155
+// Debugln logs a message at level Debug on the standard logger.
156
+func Debugln(args ...interface{}) {
157
+	std.Debugln(args...)
158
+}
159
+
160
+// Println logs a message at level Info on the standard logger.
161
+func Println(args ...interface{}) {
162
+	std.Println(args...)
163
+}
164
+
165
+// Infoln logs a message at level Info on the standard logger.
166
+func Infoln(args ...interface{}) {
167
+	std.Infoln(args...)
168
+}
169
+
170
+// Warnln logs a message at level Warn on the standard logger.
171
+func Warnln(args ...interface{}) {
172
+	std.Warnln(args...)
173
+}
174
+
175
+// Warningln logs a message at level Warn on the standard logger.
176
+func Warningln(args ...interface{}) {
177
+	std.Warningln(args...)
178
+}
179
+
180
+// Errorln logs a message at level Error on the standard logger.
181
+func Errorln(args ...interface{}) {
182
+	std.Errorln(args...)
183
+}
184
+
185
+// Panicln logs a message at level Panic on the standard logger.
186
+func Panicln(args ...interface{}) {
187
+	std.Panicln(args...)
188
+}
189
+
190
+// Fatalln logs a message at level Fatal on the standard logger.
191
+func Fatalln(args ...interface{}) {
192
+	std.Fatalln(args...)
193
+}

+ 45
- 0
vendor/src/github.com/sirupsen/logrus/formatter.go View File

@@ -0,0 +1,45 @@
1
+package logrus
2
+
3
+import "time"
4
+
5
+const defaultTimestampFormat = time.RFC3339
6
+
7
+// The Formatter interface is used to implement a custom Formatter. It takes an
8
+// `Entry`. It exposes all the fields, including the default ones:
9
+//
10
+// * `entry.Data["msg"]`. The message passed from Info, Warn, Error ..
11
+// * `entry.Data["time"]`. The timestamp.
12
+// * `entry.Data["level"]. The level the entry was logged at.
13
+//
14
+// Any additional fields added with `WithField` or `WithFields` are also in
15
+// `entry.Data`. Format is expected to return an array of bytes which are then
16
+// logged to `logger.Out`.
17
+type Formatter interface {
18
+	Format(*Entry) ([]byte, error)
19
+}
20
+
21
+// This is to not silently overwrite `time`, `msg` and `level` fields when
22
+// dumping it. If this code wasn't there doing:
23
+//
24
+//  logrus.WithField("level", 1).Info("hello")
25
+//
26
+// Would just silently drop the user provided level. Instead with this code
27
+// it'll logged as:
28
+//
29
+//  {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."}
30
+//
31
+// It's not exported because it's still using Data in an opinionated way. It's to
32
+// avoid code duplication between the two default formatters.
33
+func prefixFieldClashes(data Fields) {
34
+	if t, ok := data["time"]; ok {
35
+		data["fields.time"] = t
36
+	}
37
+
38
+	if m, ok := data["msg"]; ok {
39
+		data["fields.msg"] = m
40
+	}
41
+
42
+	if l, ok := data["level"]; ok {
43
+		data["fields.level"] = l
44
+	}
45
+}

+ 101
- 0
vendor/src/github.com/sirupsen/logrus/formatter_bench_test.go View File

@@ -0,0 +1,101 @@
1
+package logrus
2
+
3
+import (
4
+	"fmt"
5
+	"testing"
6
+	"time"
7
+)
8
+
9
+// smallFields is a small size data set for benchmarking
10
+var smallFields = Fields{
11
+	"foo":   "bar",
12
+	"baz":   "qux",
13
+	"one":   "two",
14
+	"three": "four",
15
+}
16
+
17
+// largeFields is a large size data set for benchmarking
18
+var largeFields = Fields{
19
+	"foo":       "bar",
20
+	"baz":       "qux",
21
+	"one":       "two",
22
+	"three":     "four",
23
+	"five":      "six",
24
+	"seven":     "eight",
25
+	"nine":      "ten",
26
+	"eleven":    "twelve",
27
+	"thirteen":  "fourteen",
28
+	"fifteen":   "sixteen",
29
+	"seventeen": "eighteen",
30
+	"nineteen":  "twenty",
31
+	"a":         "b",
32
+	"c":         "d",
33
+	"e":         "f",
34
+	"g":         "h",
35
+	"i":         "j",
36
+	"k":         "l",
37
+	"m":         "n",
38
+	"o":         "p",
39
+	"q":         "r",
40
+	"s":         "t",
41
+	"u":         "v",
42
+	"w":         "x",
43
+	"y":         "z",
44
+	"this":      "will",
45
+	"make":      "thirty",
46
+	"entries":   "yeah",
47
+}
48
+
49
+var errorFields = Fields{
50
+	"foo": fmt.Errorf("bar"),
51
+	"baz": fmt.Errorf("qux"),
52
+}
53
+
54
+func BenchmarkErrorTextFormatter(b *testing.B) {
55
+	doBenchmark(b, &TextFormatter{DisableColors: true}, errorFields)
56
+}
57
+
58
+func BenchmarkSmallTextFormatter(b *testing.B) {
59
+	doBenchmark(b, &TextFormatter{DisableColors: true}, smallFields)
60
+}
61
+
62
+func BenchmarkLargeTextFormatter(b *testing.B) {
63
+	doBenchmark(b, &TextFormatter{DisableColors: true}, largeFields)
64
+}
65
+
66
+func BenchmarkSmallColoredTextFormatter(b *testing.B) {
67
+	doBenchmark(b, &TextFormatter{ForceColors: true}, smallFields)
68
+}
69
+
70
+func BenchmarkLargeColoredTextFormatter(b *testing.B) {
71
+	doBenchmark(b, &TextFormatter{ForceColors: true}, largeFields)
72
+}
73
+
74
+func BenchmarkSmallJSONFormatter(b *testing.B) {
75
+	doBenchmark(b, &JSONFormatter{}, smallFields)
76
+}
77
+
78
+func BenchmarkLargeJSONFormatter(b *testing.B) {
79
+	doBenchmark(b, &JSONFormatter{}, largeFields)
80
+}
81
+
82
+func doBenchmark(b *testing.B, formatter Formatter, fields Fields) {
83
+	logger := New()
84
+
85
+	entry := &Entry{
86
+		Time:    time.Time{},
87
+		Level:   InfoLevel,
88
+		Message: "message",
89
+		Data:    fields,
90
+		Logger:  logger,
91
+	}
92
+	var d []byte
93
+	var err error
94
+	for i := 0; i < b.N; i++ {
95
+		d, err = formatter.Format(entry)
96
+		if err != nil {
97
+			b.Fatal(err)
98
+		}
99
+		b.SetBytes(int64(len(d)))
100
+	}
101
+}

+ 144
- 0
vendor/src/github.com/sirupsen/logrus/hook_test.go View File

@@ -0,0 +1,144 @@
1
+package logrus
2
+
3
+import (
4
+	"sync"
5
+	"testing"
6
+
7
+	"github.com/stretchr/testify/assert"
8
+)
9
+
10
+type TestHook struct {
11
+	Fired bool
12
+}
13
+
14
+func (hook *TestHook) Fire(entry *Entry) error {
15
+	hook.Fired = true
16
+	return nil
17
+}
18
+
19
+func (hook *TestHook) Levels() []Level {
20
+	return []Level{
21
+		DebugLevel,
22
+		InfoLevel,
23
+		WarnLevel,
24
+		ErrorLevel,
25
+		FatalLevel,
26
+		PanicLevel,
27
+	}
28
+}
29
+
30
+func TestHookFires(t *testing.T) {
31
+	hook := new(TestHook)
32
+
33
+	LogAndAssertJSON(t, func(log *Logger) {
34
+		log.Hooks.Add(hook)
35
+		assert.Equal(t, hook.Fired, false)
36
+
37
+		log.Print("test")
38
+	}, func(fields Fields) {
39
+		assert.Equal(t, hook.Fired, true)
40
+	})
41
+}
42
+
43
+type ModifyHook struct {
44
+}
45
+
46
+func (hook *ModifyHook) Fire(entry *Entry) error {
47
+	entry.Data["wow"] = "whale"
48
+	return nil
49
+}
50
+
51
+func (hook *ModifyHook) Levels() []Level {
52
+	return []Level{
53
+		DebugLevel,
54
+		InfoLevel,
55
+		WarnLevel,
56
+		ErrorLevel,
57
+		FatalLevel,
58
+		PanicLevel,
59
+	}
60
+}
61
+
62
+func TestHookCanModifyEntry(t *testing.T) {
63
+	hook := new(ModifyHook)
64
+
65
+	LogAndAssertJSON(t, func(log *Logger) {
66
+		log.Hooks.Add(hook)
67
+		log.WithField("wow", "elephant").Print("test")
68
+	}, func(fields Fields) {
69
+		assert.Equal(t, fields["wow"], "whale")
70
+	})
71
+}
72
+
73
+func TestCanFireMultipleHooks(t *testing.T) {
74
+	hook1 := new(ModifyHook)
75
+	hook2 := new(TestHook)
76
+
77
+	LogAndAssertJSON(t, func(log *Logger) {
78
+		log.Hooks.Add(hook1)
79
+		log.Hooks.Add(hook2)
80
+
81
+		log.WithField("wow", "elephant").Print("test")
82
+	}, func(fields Fields) {
83
+		assert.Equal(t, fields["wow"], "whale")
84
+		assert.Equal(t, hook2.Fired, true)
85
+	})
86
+}
87
+
88
+type ErrorHook struct {
89
+	Fired bool
90
+}
91
+
92
+func (hook *ErrorHook) Fire(entry *Entry) error {
93
+	hook.Fired = true
94
+	return nil
95
+}
96
+
97
+func (hook *ErrorHook) Levels() []Level {
98
+	return []Level{
99
+		ErrorLevel,
100
+	}
101
+}
102
+
103
+func TestErrorHookShouldntFireOnInfo(t *testing.T) {
104
+	hook := new(ErrorHook)
105
+
106
+	LogAndAssertJSON(t, func(log *Logger) {
107
+		log.Hooks.Add(hook)
108
+		log.Info("test")
109
+	}, func(fields Fields) {
110
+		assert.Equal(t, hook.Fired, false)
111
+	})
112
+}
113
+
114
+func TestErrorHookShouldFireOnError(t *testing.T) {
115
+	hook := new(ErrorHook)
116
+
117
+	LogAndAssertJSON(t, func(log *Logger) {
118
+		log.Hooks.Add(hook)
119
+		log.Error("test")
120
+	}, func(fields Fields) {
121
+		assert.Equal(t, hook.Fired, true)
122
+	})
123
+}
124
+
125
+func TestAddHookRace(t *testing.T) {
126
+	var wg sync.WaitGroup
127
+	wg.Add(2)
128
+	hook := new(ErrorHook)
129
+	LogAndAssertJSON(t, func(log *Logger) {
130
+		go func() {
131
+			defer wg.Done()
132
+			log.AddHook(hook)
133
+		}()
134
+		go func() {
135
+			defer wg.Done()
136
+			log.Error("test")
137
+		}()
138
+		wg.Wait()
139
+	}, func(fields Fields) {
140
+		// the line may have been logged
141
+		// before the hook was added, so we can't
142
+		// actually assert on the hook
143
+	})
144
+}

+ 34
- 0
vendor/src/github.com/sirupsen/logrus/hooks.go View File

@@ -0,0 +1,34 @@
1
+package logrus
2
+
3
+// A hook to be fired when logging on the logging levels returned from
4
+// `Levels()` on your implementation of the interface. Note that this is not
5
+// fired in a goroutine or a channel with workers, you should handle such
6
+// functionality yourself if your call is non-blocking and you don't wish for
7
+// the logging calls for levels returned from `Levels()` to block.
8
+type Hook interface {
9
+	Levels() []Level
10
+	Fire(*Entry) error
11
+}
12
+
13
+// Internal type for storing the hooks on a logger instance.
14
+type LevelHooks map[Level][]Hook
15
+
16
+// Add a hook to an instance of logger. This is called with
17
+// `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface.
18
+func (hooks LevelHooks) Add(hook Hook) {
19
+	for _, level := range hook.Levels() {
20
+		hooks[level] = append(hooks[level], hook)
21
+	}
22
+}
23
+
24
+// Fire all the hooks for the passed level. Used by `entry.log` to fire
25
+// appropriate hooks for a log entry.
26
+func (hooks LevelHooks) Fire(level Level, entry *Entry) error {
27
+	for _, hook := range hooks[level] {
28
+		if err := hook.Fire(entry); err != nil {
29
+			return err
30
+		}
31
+	}
32
+
33
+	return nil
34
+}

+ 39
- 0
vendor/src/github.com/sirupsen/logrus/hooks/syslog/README.md View File

@@ -0,0 +1,39 @@
1
+# Syslog Hooks for Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>
2
+
3
+## Usage
4
+
5
+```go
6
+import (
7
+  "log/syslog"
8
+  "github.com/sirupsen/logrus"
9
+  lSyslog "github.com/sirupsen/logrus/hooks/syslog"
10
+)
11
+
12
+func main() {
13
+  log       := logrus.New()
14
+  hook, err := lSyslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
15
+
16
+  if err == nil {
17
+    log.Hooks.Add(hook)
18
+  }
19
+}
20
+```
21
+
22
+If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). Just assign empty string to the first two parameters of `NewSyslogHook`. It should look like the following.
23
+
24
+```go
25
+import (
26
+  "log/syslog"
27
+  "github.com/sirupsen/logrus"
28
+  lSyslog "github.com/sirupsen/logrus/hooks/syslog"
29
+)
30
+
31
+func main() {
32
+  log       := logrus.New()
33
+  hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
34
+
35
+  if err == nil {
36
+    log.Hooks.Add(hook)
37
+  }
38
+}
39
+```

+ 55
- 0
vendor/src/github.com/sirupsen/logrus/hooks/syslog/syslog.go View File

@@ -0,0 +1,55 @@
1
+// +build !windows,!nacl,!plan9
2
+
3
+package syslog
4
+
5
+import (
6
+	"fmt"
7
+	"log/syslog"
8
+	"os"
9
+
10
+	"github.com/sirupsen/logrus"
11
+)
12
+
13
+// SyslogHook to send logs via syslog.
14
+type SyslogHook struct {
15
+	Writer        *syslog.Writer
16
+	SyslogNetwork string
17
+	SyslogRaddr   string
18
+}
19
+
20
+// Creates a hook to be added to an instance of logger. This is called with
21
+// `hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_DEBUG, "")`
22
+// `if err == nil { log.Hooks.Add(hook) }`
23
+func NewSyslogHook(network, raddr string, priority syslog.Priority, tag string) (*SyslogHook, error) {
24
+	w, err := syslog.Dial(network, raddr, priority, tag)
25
+	return &SyslogHook{w, network, raddr}, err
26
+}
27
+
28
+func (hook *SyslogHook) Fire(entry *logrus.Entry) error {
29
+	line, err := entry.String()
30
+	if err != nil {
31
+		fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
32
+		return err
33
+	}
34
+
35
+	switch entry.Level {
36
+	case logrus.PanicLevel:
37
+		return hook.Writer.Crit(line)
38
+	case logrus.FatalLevel:
39
+		return hook.Writer.Crit(line)
40
+	case logrus.ErrorLevel:
41
+		return hook.Writer.Err(line)
42
+	case logrus.WarnLevel:
43
+		return hook.Writer.Warning(line)
44
+	case logrus.InfoLevel:
45
+		return hook.Writer.Info(line)
46
+	case logrus.DebugLevel:
47
+		return hook.Writer.Debug(line)
48
+	default:
49
+		return nil
50
+	}
51
+}
52
+
53
+func (hook *SyslogHook) Levels() []logrus.Level {
54
+	return logrus.AllLevels
55
+}

+ 27
- 0
vendor/src/github.com/sirupsen/logrus/hooks/syslog/syslog_test.go View File

@@ -0,0 +1,27 @@
1
+package syslog
2
+
3
+import (
4
+	"log/syslog"
5
+	"testing"
6
+
7
+	"github.com/sirupsen/logrus"
8
+)
9
+
10
+func TestLocalhostAddAndPrint(t *testing.T) {
11
+	log := logrus.New()
12
+	hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
13
+
14
+	if err != nil {
15
+		t.Errorf("Unable to connect to local syslog.")
16
+	}
17
+
18
+	log.Hooks.Add(hook)
19
+
20
+	for _, level := range hook.Levels() {
21
+		if len(log.Hooks[level]) != 1 {
22
+			t.Errorf("SyslogHook was not added. The length of log.Hooks[%v]: %v", level, len(log.Hooks[level]))
23
+		}
24
+	}
25
+
26
+	log.Info("Congratulations!")
27
+}

+ 95
- 0
vendor/src/github.com/sirupsen/logrus/hooks/test/test.go View File

@@ -0,0 +1,95 @@
1
+// The Test package is used for testing logrus. It is here for backwards
2
+// compatibility from when logrus' organization was upper-case. Please use
3
+// lower-case logrus and the `null` package instead of this one.
4
+package test
5
+
6
+import (
7
+	"io/ioutil"
8
+	"sync"
9
+
10
+	"github.com/sirupsen/logrus"
11
+)
12
+
13
+// Hook is a hook designed for dealing with logs in test scenarios.
14
+type Hook struct {
15
+	// Entries is an array of all entries that have been received by this hook.
16
+	// For safe access, use the AllEntries() method, rather than reading this
17
+	// value directly.
18
+	Entries []*logrus.Entry
19
+	mu      sync.RWMutex
20
+}
21
+
22
+// NewGlobal installs a test hook for the global logger.
23
+func NewGlobal() *Hook {
24
+
25
+	hook := new(Hook)
26
+	logrus.AddHook(hook)
27
+
28
+	return hook
29
+
30
+}
31
+
32
+// NewLocal installs a test hook for a given local logger.
33
+func NewLocal(logger *logrus.Logger) *Hook {
34
+
35
+	hook := new(Hook)
36
+	logger.Hooks.Add(hook)
37
+
38
+	return hook
39
+
40
+}
41
+
42
+// NewNullLogger creates a discarding logger and installs the test hook.
43
+func NewNullLogger() (*logrus.Logger, *Hook) {
44
+
45
+	logger := logrus.New()
46
+	logger.Out = ioutil.Discard
47
+
48
+	return logger, NewLocal(logger)
49
+
50
+}
51
+
52
+func (t *Hook) Fire(e *logrus.Entry) error {
53
+	t.mu.Lock()
54
+	defer t.mu.Unlock()
55
+	t.Entries = append(t.Entries, e)
56
+	return nil
57
+}
58
+
59
+func (t *Hook) Levels() []logrus.Level {
60
+	return logrus.AllLevels
61
+}
62
+
63
+// LastEntry returns the last entry that was logged or nil.
64
+func (t *Hook) LastEntry() *logrus.Entry {
65
+	t.mu.RLock()
66
+	defer t.mu.RUnlock()
67
+	i := len(t.Entries) - 1
68
+	if i < 0 {
69
+		return nil
70
+	}
71
+	// Make a copy, for safety
72
+	e := *t.Entries[i]
73
+	return &e
74
+}
75
+
76
+// AllEntries returns all entries that were logged.
77
+func (t *Hook) AllEntries() []*logrus.Entry {
78
+	t.mu.RLock()
79
+	defer t.mu.RUnlock()
80
+	// Make a copy so the returned value won't race with future log requests
81
+	entries := make([]*logrus.Entry, len(t.Entries))
82
+	for i, entry := range t.Entries {
83
+		// Make a copy, for safety
84
+		e := *entry
85
+		entries[i] = &e
86
+	}
87
+	return entries
88
+}
89
+
90
+// Reset removes all Entries from this test hook.
91
+func (t *Hook) Reset() {
92
+	t.mu.Lock()
93
+	defer t.mu.Unlock()
94
+	t.Entries = make([]*logrus.Entry, 0)
95
+}

+ 39
- 0
vendor/src/github.com/sirupsen/logrus/hooks/test/test_test.go View File

@@ -0,0 +1,39 @@
1
+package test
2
+
3
+import (
4
+	"testing"
5
+
6
+	"github.com/sirupsen/logrus"
7
+	"github.com/stretchr/testify/assert"
8
+)
9
+
10
+func TestAllHooks(t *testing.T) {
11
+
12
+	assert := assert.New(t)
13
+
14
+	logger, hook := NewNullLogger()
15
+	assert.Nil(hook.LastEntry())
16
+	assert.Equal(0, len(hook.Entries))
17
+
18
+	logger.Error("Hello error")
19
+	assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
20
+	assert.Equal("Hello error", hook.LastEntry().Message)
21
+	assert.Equal(1, len(hook.Entries))
22
+
23
+	logger.Warn("Hello warning")
24
+	assert.Equal(logrus.WarnLevel, hook.LastEntry().Level)
25
+	assert.Equal("Hello warning", hook.LastEntry().Message)
26
+	assert.Equal(2, len(hook.Entries))
27
+
28
+	hook.Reset()
29
+	assert.Nil(hook.LastEntry())
30
+	assert.Equal(0, len(hook.Entries))
31
+
32
+	hook = NewGlobal()
33
+
34
+	logrus.Error("Hello error")
35
+	assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
36
+	assert.Equal("Hello error", hook.LastEntry().Message)
37
+	assert.Equal(1, len(hook.Entries))
38
+
39
+}

+ 79
- 0
vendor/src/github.com/sirupsen/logrus/json_formatter.go View File

@@ -0,0 +1,79 @@
1
+package logrus
2
+
3
+import (
4
+	"encoding/json"
5
+	"fmt"
6
+)
7
+
8
+type fieldKey string
9
+
10
+// FieldMap allows customization of the key names for default fields.
11
+type FieldMap map[fieldKey]string
12
+
13
+// Default key names for the default fields
14
+const (
15
+	FieldKeyMsg   = "msg"
16
+	FieldKeyLevel = "level"
17
+	FieldKeyTime  = "time"
18
+)
19
+
20
+func (f FieldMap) resolve(key fieldKey) string {
21
+	if k, ok := f[key]; ok {
22
+		return k
23
+	}
24
+
25
+	return string(key)
26
+}
27
+
28
+// JSONFormatter formats logs into parsable json
29
+type JSONFormatter struct {
30
+	// TimestampFormat sets the format used for marshaling timestamps.
31
+	TimestampFormat string
32
+
33
+	// DisableTimestamp allows disabling automatic timestamps in output
34
+	DisableTimestamp bool
35
+
36
+	// FieldMap allows users to customize the names of keys for default fields.
37
+	// As an example:
38
+	// formatter := &JSONFormatter{
39
+	//   	FieldMap: FieldMap{
40
+	// 		 FieldKeyTime: "@timestamp",
41
+	// 		 FieldKeyLevel: "@level",
42
+	// 		 FieldKeyMsg: "@message",
43
+	//    },