Bladeren bron

Use logrus instead of log

Brendan Abolivier 7 jaren geleden
bovenliggende
commit
9dc9eb11f0
Getekend door: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
33 gewijzigde bestanden met toevoegingen van 3674 en 2 verwijderingen
  1. 3
    2
      src/metrics-alerting/main.go
  2. 113
    0
      vendor/src/github.com/sirupsen/logrus/CHANGELOG.md
  3. 21
    0
      vendor/src/github.com/sirupsen/logrus/LICENSE
  4. 509
    0
      vendor/src/github.com/sirupsen/logrus/README.md
  5. 64
    0
      vendor/src/github.com/sirupsen/logrus/alt_exit.go
  6. 83
    0
      vendor/src/github.com/sirupsen/logrus/alt_exit_test.go
  7. 14
    0
      vendor/src/github.com/sirupsen/logrus/appveyor.yml
  8. 26
    0
      vendor/src/github.com/sirupsen/logrus/doc.go
  9. 279
    0
      vendor/src/github.com/sirupsen/logrus/entry.go
  10. 77
    0
      vendor/src/github.com/sirupsen/logrus/entry_test.go
  11. 69
    0
      vendor/src/github.com/sirupsen/logrus/example_basic_test.go
  12. 35
    0
      vendor/src/github.com/sirupsen/logrus/example_hook_test.go
  13. 193
    0
      vendor/src/github.com/sirupsen/logrus/exported.go
  14. 45
    0
      vendor/src/github.com/sirupsen/logrus/formatter.go
  15. 101
    0
      vendor/src/github.com/sirupsen/logrus/formatter_bench_test.go
  16. 144
    0
      vendor/src/github.com/sirupsen/logrus/hook_test.go
  17. 34
    0
      vendor/src/github.com/sirupsen/logrus/hooks.go
  18. 39
    0
      vendor/src/github.com/sirupsen/logrus/hooks/syslog/README.md
  19. 55
    0
      vendor/src/github.com/sirupsen/logrus/hooks/syslog/syslog.go
  20. 27
    0
      vendor/src/github.com/sirupsen/logrus/hooks/syslog/syslog_test.go
  21. 95
    0
      vendor/src/github.com/sirupsen/logrus/hooks/test/test.go
  22. 39
    0
      vendor/src/github.com/sirupsen/logrus/hooks/test/test_test.go
  23. 79
    0
      vendor/src/github.com/sirupsen/logrus/json_formatter.go
  24. 199
    0
      vendor/src/github.com/sirupsen/logrus/json_formatter_test.go
  25. 323
    0
      vendor/src/github.com/sirupsen/logrus/logger.go
  26. 61
    0
      vendor/src/github.com/sirupsen/logrus/logger_bench_test.go
  27. 143
    0
      vendor/src/github.com/sirupsen/logrus/logrus.go
  28. 386
    0
      vendor/src/github.com/sirupsen/logrus/logrus_test.go
  29. 10
    0
      vendor/src/github.com/sirupsen/logrus/terminal_bsd.go
  30. 14
    0
      vendor/src/github.com/sirupsen/logrus/terminal_linux.go
  31. 191
    0
      vendor/src/github.com/sirupsen/logrus/text_formatter.go
  32. 141
    0
      vendor/src/github.com/sirupsen/logrus/text_formatter_test.go
  33. 62
    0
      vendor/src/github.com/sirupsen/logrus/writer.go

+ 3
- 2
src/metrics-alerting/main.go Bestand weergeven

3
 import (
3
 import (
4
 	"flag"
4
 	"flag"
5
 	"fmt"
5
 	"fmt"
6
-	"log"
7
 
6
 
8
 	"metrics-alerting/alert"
7
 	"metrics-alerting/alert"
9
 	"metrics-alerting/config"
8
 	"metrics-alerting/config"
10
 	"metrics-alerting/warp10"
9
 	"metrics-alerting/warp10"
10
+
11
+	"github.com/sirupsen/logrus"
11
 )
12
 )
12
 
13
 
13
 var (
14
 var (
37
 		}
38
 		}
38
 
39
 
39
 		if err != nil {
40
 		if err != nil {
40
-			log.Fatal(err)
41
+			logrus.Error(err)
41
 		}
42
 		}
42
 	}
43
 	}
43
 }
44
 }

+ 113
- 0
vendor/src/github.com/sirupsen/logrus/CHANGELOG.md Bestand weergeven

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

+ 21
- 0
vendor/src/github.com/sirupsen/logrus/LICENSE Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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 Bestand weergeven

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
+	//    },
44
+	// }
45
+	FieldMap FieldMap
46
+}
47
+
48
+// Format renders a single log entry
49
+func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
50
+	data := make(Fields, len(entry.Data)+3)
51
+	for k, v := range entry.Data {
52
+		switch v := v.(type) {
53
+		case error:
54
+			// Otherwise errors are ignored by `encoding/json`
55
+			// https://github.com/sirupsen/logrus/issues/137
56
+			data[k] = v.Error()
57
+		default:
58
+			data[k] = v
59
+		}
60
+	}
61
+	prefixFieldClashes(data)
62
+
63
+	timestampFormat := f.TimestampFormat
64
+	if timestampFormat == "" {
65
+		timestampFormat = defaultTimestampFormat
66
+	}
67
+
68
+	if !f.DisableTimestamp {
69
+		data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat)
70
+	}
71
+	data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message
72
+	data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String()
73
+
74
+	serialized, err := json.Marshal(data)
75
+	if err != nil {
76
+		return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
77
+	}
78
+	return append(serialized, '\n'), nil
79
+}

+ 199
- 0
vendor/src/github.com/sirupsen/logrus/json_formatter_test.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"encoding/json"
5
+	"errors"
6
+	"strings"
7
+	"testing"
8
+)
9
+
10
+func TestErrorNotLost(t *testing.T) {
11
+	formatter := &JSONFormatter{}
12
+
13
+	b, err := formatter.Format(WithField("error", errors.New("wild walrus")))
14
+	if err != nil {
15
+		t.Fatal("Unable to format entry: ", err)
16
+	}
17
+
18
+	entry := make(map[string]interface{})
19
+	err = json.Unmarshal(b, &entry)
20
+	if err != nil {
21
+		t.Fatal("Unable to unmarshal formatted entry: ", err)
22
+	}
23
+
24
+	if entry["error"] != "wild walrus" {
25
+		t.Fatal("Error field not set")
26
+	}
27
+}
28
+
29
+func TestErrorNotLostOnFieldNotNamedError(t *testing.T) {
30
+	formatter := &JSONFormatter{}
31
+
32
+	b, err := formatter.Format(WithField("omg", errors.New("wild walrus")))
33
+	if err != nil {
34
+		t.Fatal("Unable to format entry: ", err)
35
+	}
36
+
37
+	entry := make(map[string]interface{})
38
+	err = json.Unmarshal(b, &entry)
39
+	if err != nil {
40
+		t.Fatal("Unable to unmarshal formatted entry: ", err)
41
+	}
42
+
43
+	if entry["omg"] != "wild walrus" {
44
+		t.Fatal("Error field not set")
45
+	}
46
+}
47
+
48
+func TestFieldClashWithTime(t *testing.T) {
49
+	formatter := &JSONFormatter{}
50
+
51
+	b, err := formatter.Format(WithField("time", "right now!"))
52
+	if err != nil {
53
+		t.Fatal("Unable to format entry: ", err)
54
+	}
55
+
56
+	entry := make(map[string]interface{})
57
+	err = json.Unmarshal(b, &entry)
58
+	if err != nil {
59
+		t.Fatal("Unable to unmarshal formatted entry: ", err)
60
+	}
61
+
62
+	if entry["fields.time"] != "right now!" {
63
+		t.Fatal("fields.time not set to original time field")
64
+	}
65
+
66
+	if entry["time"] != "0001-01-01T00:00:00Z" {
67
+		t.Fatal("time field not set to current time, was: ", entry["time"])
68
+	}
69
+}
70
+
71
+func TestFieldClashWithMsg(t *testing.T) {
72
+	formatter := &JSONFormatter{}
73
+
74
+	b, err := formatter.Format(WithField("msg", "something"))
75
+	if err != nil {
76
+		t.Fatal("Unable to format entry: ", err)
77
+	}
78
+
79
+	entry := make(map[string]interface{})
80
+	err = json.Unmarshal(b, &entry)
81
+	if err != nil {
82
+		t.Fatal("Unable to unmarshal formatted entry: ", err)
83
+	}
84
+
85
+	if entry["fields.msg"] != "something" {
86
+		t.Fatal("fields.msg not set to original msg field")
87
+	}
88
+}
89
+
90
+func TestFieldClashWithLevel(t *testing.T) {
91
+	formatter := &JSONFormatter{}
92
+
93
+	b, err := formatter.Format(WithField("level", "something"))
94
+	if err != nil {
95
+		t.Fatal("Unable to format entry: ", err)
96
+	}
97
+
98
+	entry := make(map[string]interface{})
99
+	err = json.Unmarshal(b, &entry)
100
+	if err != nil {
101
+		t.Fatal("Unable to unmarshal formatted entry: ", err)
102
+	}
103
+
104
+	if entry["fields.level"] != "something" {
105
+		t.Fatal("fields.level not set to original level field")
106
+	}
107
+}
108
+
109
+func TestJSONEntryEndsWithNewline(t *testing.T) {
110
+	formatter := &JSONFormatter{}
111
+
112
+	b, err := formatter.Format(WithField("level", "something"))
113
+	if err != nil {
114
+		t.Fatal("Unable to format entry: ", err)
115
+	}
116
+
117
+	if b[len(b)-1] != '\n' {
118
+		t.Fatal("Expected JSON log entry to end with a newline")
119
+	}
120
+}
121
+
122
+func TestJSONMessageKey(t *testing.T) {
123
+	formatter := &JSONFormatter{
124
+		FieldMap: FieldMap{
125
+			FieldKeyMsg: "message",
126
+		},
127
+	}
128
+
129
+	b, err := formatter.Format(&Entry{Message: "oh hai"})
130
+	if err != nil {
131
+		t.Fatal("Unable to format entry: ", err)
132
+	}
133
+	s := string(b)
134
+	if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) {
135
+		t.Fatal("Expected JSON to format message key")
136
+	}
137
+}
138
+
139
+func TestJSONLevelKey(t *testing.T) {
140
+	formatter := &JSONFormatter{
141
+		FieldMap: FieldMap{
142
+			FieldKeyLevel: "somelevel",
143
+		},
144
+	}
145
+
146
+	b, err := formatter.Format(WithField("level", "something"))
147
+	if err != nil {
148
+		t.Fatal("Unable to format entry: ", err)
149
+	}
150
+	s := string(b)
151
+	if !strings.Contains(s, "somelevel") {
152
+		t.Fatal("Expected JSON to format level key")
153
+	}
154
+}
155
+
156
+func TestJSONTimeKey(t *testing.T) {
157
+	formatter := &JSONFormatter{
158
+		FieldMap: FieldMap{
159
+			FieldKeyTime: "timeywimey",
160
+		},
161
+	}
162
+
163
+	b, err := formatter.Format(WithField("level", "something"))
164
+	if err != nil {
165
+		t.Fatal("Unable to format entry: ", err)
166
+	}
167
+	s := string(b)
168
+	if !strings.Contains(s, "timeywimey") {
169
+		t.Fatal("Expected JSON to format time key")
170
+	}
171
+}
172
+
173
+func TestJSONDisableTimestamp(t *testing.T) {
174
+	formatter := &JSONFormatter{
175
+		DisableTimestamp: true,
176
+	}
177
+
178
+	b, err := formatter.Format(WithField("level", "something"))
179
+	if err != nil {
180
+		t.Fatal("Unable to format entry: ", err)
181
+	}
182
+	s := string(b)
183
+	if strings.Contains(s, FieldKeyTime) {
184
+		t.Error("Did not prevent timestamp", s)
185
+	}
186
+}
187
+
188
+func TestJSONEnableTimestamp(t *testing.T) {
189
+	formatter := &JSONFormatter{}
190
+
191
+	b, err := formatter.Format(WithField("level", "something"))
192
+	if err != nil {
193
+		t.Fatal("Unable to format entry: ", err)
194
+	}
195
+	s := string(b)
196
+	if !strings.Contains(s, FieldKeyTime) {
197
+		t.Error("Timestamp not present", s)
198
+	}
199
+}

+ 323
- 0
vendor/src/github.com/sirupsen/logrus/logger.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"io"
5
+	"os"
6
+	"sync"
7
+	"sync/atomic"
8
+)
9
+
10
+type Logger struct {
11
+	// The logs are `io.Copy`'d to this in a mutex. It's common to set this to a
12
+	// file, or leave it default which is `os.Stderr`. You can also set this to
13
+	// something more adventorous, such as logging to Kafka.
14
+	Out io.Writer
15
+	// Hooks for the logger instance. These allow firing events based on logging
16
+	// levels and log entries. For example, to send errors to an error tracking
17
+	// service, log to StatsD or dump the core on fatal errors.
18
+	Hooks LevelHooks
19
+	// All log entries pass through the formatter before logged to Out. The
20
+	// included formatters are `TextFormatter` and `JSONFormatter` for which
21
+	// TextFormatter is the default. In development (when a TTY is attached) it
22
+	// logs with colors, but to a file it wouldn't. You can easily implement your
23
+	// own that implements the `Formatter` interface, see the `README` or included
24
+	// formatters for examples.
25
+	Formatter Formatter
26
+	// The logging level the logger should log at. This is typically (and defaults
27
+	// to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be
28
+	// logged.
29
+	Level Level
30
+	// Used to sync writing to the log. Locking is enabled by Default
31
+	mu MutexWrap
32
+	// Reusable empty entry
33
+	entryPool sync.Pool
34
+}
35
+
36
+type MutexWrap struct {
37
+	lock     sync.Mutex
38
+	disabled bool
39
+}
40
+
41
+func (mw *MutexWrap) Lock() {
42
+	if !mw.disabled {
43
+		mw.lock.Lock()
44
+	}
45
+}
46
+
47
+func (mw *MutexWrap) Unlock() {
48
+	if !mw.disabled {
49
+		mw.lock.Unlock()
50
+	}
51
+}
52
+
53
+func (mw *MutexWrap) Disable() {
54
+	mw.disabled = true
55
+}
56
+
57
+// Creates a new logger. Configuration should be set by changing `Formatter`,
58
+// `Out` and `Hooks` directly on the default logger instance. You can also just
59
+// instantiate your own:
60
+//
61
+//    var log = &Logger{
62
+//      Out: os.Stderr,
63
+//      Formatter: new(JSONFormatter),
64
+//      Hooks: make(LevelHooks),
65
+//      Level: logrus.DebugLevel,
66
+//    }
67
+//
68
+// It's recommended to make this a global instance called `log`.
69
+func New() *Logger {
70
+	return &Logger{
71
+		Out:       os.Stderr,
72
+		Formatter: new(TextFormatter),
73
+		Hooks:     make(LevelHooks),
74
+		Level:     InfoLevel,
75
+	}
76
+}
77
+
78
+func (logger *Logger) newEntry() *Entry {
79
+	entry, ok := logger.entryPool.Get().(*Entry)
80
+	if ok {
81
+		return entry
82
+	}
83
+	return NewEntry(logger)
84
+}
85
+
86
+func (logger *Logger) releaseEntry(entry *Entry) {
87
+	logger.entryPool.Put(entry)
88
+}
89
+
90
+// Adds a field to the log entry, note that it doesn't log until you call
91
+// Debug, Print, Info, Warn, Fatal or Panic. It only creates a log entry.
92
+// If you want multiple fields, use `WithFields`.
93
+func (logger *Logger) WithField(key string, value interface{}) *Entry {
94
+	entry := logger.newEntry()
95
+	defer logger.releaseEntry(entry)
96
+	return entry.WithField(key, value)
97
+}
98
+
99
+// Adds a struct of fields to the log entry. All it does is call `WithField` for
100
+// each `Field`.
101
+func (logger *Logger) WithFields(fields Fields) *Entry {
102
+	entry := logger.newEntry()
103
+	defer logger.releaseEntry(entry)
104
+	return entry.WithFields(fields)
105
+}
106
+
107
+// Add an error as single field to the log entry.  All it does is call
108
+// `WithError` for the given `error`.
109
+func (logger *Logger) WithError(err error) *Entry {
110
+	entry := logger.newEntry()
111
+	defer logger.releaseEntry(entry)
112
+	return entry.WithError(err)
113
+}
114
+
115
+func (logger *Logger) Debugf(format string, args ...interface{}) {
116
+	if logger.level() >= DebugLevel {
117
+		entry := logger.newEntry()
118
+		entry.Debugf(format, args...)
119
+		logger.releaseEntry(entry)
120
+	}
121
+}
122
+
123
+func (logger *Logger) Infof(format string, args ...interface{}) {
124
+	if logger.level() >= InfoLevel {
125
+		entry := logger.newEntry()
126
+		entry.Infof(format, args...)
127
+		logger.releaseEntry(entry)
128
+	}
129
+}
130
+
131
+func (logger *Logger) Printf(format string, args ...interface{}) {
132
+	entry := logger.newEntry()
133
+	entry.Printf(format, args...)
134
+	logger.releaseEntry(entry)
135
+}
136
+
137
+func (logger *Logger) Warnf(format string, args ...interface{}) {
138
+	if logger.level() >= WarnLevel {
139
+		entry := logger.newEntry()
140
+		entry.Warnf(format, args...)
141
+		logger.releaseEntry(entry)
142
+	}
143
+}
144
+
145
+func (logger *Logger) Warningf(format string, args ...interface{}) {
146
+	if logger.level() >= WarnLevel {
147
+		entry := logger.newEntry()
148
+		entry.Warnf(format, args...)
149
+		logger.releaseEntry(entry)
150
+	}
151
+}
152
+
153
+func (logger *Logger) Errorf(format string, args ...interface{}) {
154
+	if logger.level() >= ErrorLevel {
155
+		entry := logger.newEntry()
156
+		entry.Errorf(format, args...)
157
+		logger.releaseEntry(entry)
158
+	}
159
+}
160
+
161
+func (logger *Logger) Fatalf(format string, args ...interface{}) {
162
+	if logger.level() >= FatalLevel {
163
+		entry := logger.newEntry()
164
+		entry.Fatalf(format, args...)
165
+		logger.releaseEntry(entry)
166
+	}
167
+	Exit(1)
168
+}
169
+
170
+func (logger *Logger) Panicf(format string, args ...interface{}) {
171
+	if logger.level() >= PanicLevel {
172
+		entry := logger.newEntry()
173
+		entry.Panicf(format, args...)
174
+		logger.releaseEntry(entry)
175
+	}
176
+}
177
+
178
+func (logger *Logger) Debug(args ...interface{}) {
179
+	if logger.level() >= DebugLevel {
180
+		entry := logger.newEntry()
181
+		entry.Debug(args...)
182
+		logger.releaseEntry(entry)
183
+	}
184
+}
185
+
186
+func (logger *Logger) Info(args ...interface{}) {
187
+	if logger.level() >= InfoLevel {
188
+		entry := logger.newEntry()
189
+		entry.Info(args...)
190
+		logger.releaseEntry(entry)
191
+	}
192
+}
193
+
194
+func (logger *Logger) Print(args ...interface{}) {
195
+	entry := logger.newEntry()
196
+	entry.Info(args...)
197
+	logger.releaseEntry(entry)
198
+}
199
+
200
+func (logger *Logger) Warn(args ...interface{}) {
201
+	if logger.level() >= WarnLevel {
202
+		entry := logger.newEntry()
203
+		entry.Warn(args...)
204
+		logger.releaseEntry(entry)
205
+	}
206
+}
207
+
208
+func (logger *Logger) Warning(args ...interface{}) {
209
+	if logger.level() >= WarnLevel {
210
+		entry := logger.newEntry()
211
+		entry.Warn(args...)
212
+		logger.releaseEntry(entry)
213
+	}
214
+}
215
+
216
+func (logger *Logger) Error(args ...interface{}) {
217
+	if logger.level() >= ErrorLevel {
218
+		entry := logger.newEntry()
219
+		entry.Error(args...)
220
+		logger.releaseEntry(entry)
221
+	}
222
+}
223
+
224
+func (logger *Logger) Fatal(args ...interface{}) {
225
+	if logger.level() >= FatalLevel {
226
+		entry := logger.newEntry()
227
+		entry.Fatal(args...)
228
+		logger.releaseEntry(entry)
229
+	}
230
+	Exit(1)
231
+}
232
+
233
+func (logger *Logger) Panic(args ...interface{}) {
234
+	if logger.level() >= PanicLevel {
235
+		entry := logger.newEntry()
236
+		entry.Panic(args...)
237
+		logger.releaseEntry(entry)
238
+	}
239
+}
240
+
241
+func (logger *Logger) Debugln(args ...interface{}) {
242
+	if logger.level() >= DebugLevel {
243
+		entry := logger.newEntry()
244
+		entry.Debugln(args...)
245
+		logger.releaseEntry(entry)
246
+	}
247
+}
248
+
249
+func (logger *Logger) Infoln(args ...interface{}) {
250
+	if logger.level() >= InfoLevel {
251
+		entry := logger.newEntry()
252
+		entry.Infoln(args...)
253
+		logger.releaseEntry(entry)
254
+	}
255
+}
256
+
257
+func (logger *Logger) Println(args ...interface{}) {
258
+	entry := logger.newEntry()
259
+	entry.Println(args...)
260
+	logger.releaseEntry(entry)
261
+}
262
+
263
+func (logger *Logger) Warnln(args ...interface{}) {
264
+	if logger.level() >= WarnLevel {
265
+		entry := logger.newEntry()
266
+		entry.Warnln(args...)
267
+		logger.releaseEntry(entry)
268
+	}
269
+}
270
+
271
+func (logger *Logger) Warningln(args ...interface{}) {
272
+	if logger.level() >= WarnLevel {
273
+		entry := logger.newEntry()
274
+		entry.Warnln(args...)
275
+		logger.releaseEntry(entry)
276
+	}
277
+}
278
+
279
+func (logger *Logger) Errorln(args ...interface{}) {
280
+	if logger.level() >= ErrorLevel {
281
+		entry := logger.newEntry()
282
+		entry.Errorln(args...)
283
+		logger.releaseEntry(entry)
284
+	}
285
+}
286
+
287
+func (logger *Logger) Fatalln(args ...interface{}) {
288
+	if logger.level() >= FatalLevel {
289
+		entry := logger.newEntry()
290
+		entry.Fatalln(args...)
291
+		logger.releaseEntry(entry)
292
+	}
293
+	Exit(1)
294
+}
295
+
296
+func (logger *Logger) Panicln(args ...interface{}) {
297
+	if logger.level() >= PanicLevel {
298
+		entry := logger.newEntry()
299
+		entry.Panicln(args...)
300
+		logger.releaseEntry(entry)
301
+	}
302
+}
303
+
304
+//When file is opened with appending mode, it's safe to
305
+//write concurrently to a file (within 4k message on Linux).
306
+//In these cases user can choose to disable the lock.
307
+func (logger *Logger) SetNoLock() {
308
+	logger.mu.Disable()
309
+}
310
+
311
+func (logger *Logger) level() Level {
312
+	return Level(atomic.LoadUint32((*uint32)(&logger.Level)))
313
+}
314
+
315
+func (logger *Logger) SetLevel(level Level) {
316
+	atomic.StoreUint32((*uint32)(&logger.Level), uint32(level))
317
+}
318
+
319
+func (logger *Logger) AddHook(hook Hook) {
320
+	logger.mu.Lock()
321
+	defer logger.mu.Unlock()
322
+	logger.Hooks.Add(hook)
323
+}

+ 61
- 0
vendor/src/github.com/sirupsen/logrus/logger_bench_test.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"os"
5
+	"testing"
6
+)
7
+
8
+// smallFields is a small size data set for benchmarking
9
+var loggerFields = Fields{
10
+	"foo":   "bar",
11
+	"baz":   "qux",
12
+	"one":   "two",
13
+	"three": "four",
14
+}
15
+
16
+func BenchmarkDummyLogger(b *testing.B) {
17
+	nullf, err := os.OpenFile("/dev/null", os.O_WRONLY, 0666)
18
+	if err != nil {
19
+		b.Fatalf("%v", err)
20
+	}
21
+	defer nullf.Close()
22
+	doLoggerBenchmark(b, nullf, &TextFormatter{DisableColors: true}, smallFields)
23
+}
24
+
25
+func BenchmarkDummyLoggerNoLock(b *testing.B) {
26
+	nullf, err := os.OpenFile("/dev/null", os.O_WRONLY|os.O_APPEND, 0666)
27
+	if err != nil {
28
+		b.Fatalf("%v", err)
29
+	}
30
+	defer nullf.Close()
31
+	doLoggerBenchmarkNoLock(b, nullf, &TextFormatter{DisableColors: true}, smallFields)
32
+}
33
+
34
+func doLoggerBenchmark(b *testing.B, out *os.File, formatter Formatter, fields Fields) {
35
+	logger := Logger{
36
+		Out:       out,
37
+		Level:     InfoLevel,
38
+		Formatter: formatter,
39
+	}
40
+	entry := logger.WithFields(fields)
41
+	b.RunParallel(func(pb *testing.PB) {
42
+		for pb.Next() {
43
+			entry.Info("aaa")
44
+		}
45
+	})
46
+}
47
+
48
+func doLoggerBenchmarkNoLock(b *testing.B, out *os.File, formatter Formatter, fields Fields) {
49
+	logger := Logger{
50
+		Out:       out,
51
+		Level:     InfoLevel,
52
+		Formatter: formatter,
53
+	}
54
+	logger.SetNoLock()
55
+	entry := logger.WithFields(fields)
56
+	b.RunParallel(func(pb *testing.PB) {
57
+		for pb.Next() {
58
+			entry.Info("aaa")
59
+		}
60
+	})
61
+}

+ 143
- 0
vendor/src/github.com/sirupsen/logrus/logrus.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"fmt"
5
+	"log"
6
+	"strings"
7
+)
8
+
9
+// Fields type, used to pass to `WithFields`.
10
+type Fields map[string]interface{}
11
+
12
+// Level type
13
+type Level uint32
14
+
15
+// Convert the Level to a string. E.g. PanicLevel becomes "panic".
16
+func (level Level) String() string {
17
+	switch level {
18
+	case DebugLevel:
19
+		return "debug"
20
+	case InfoLevel:
21
+		return "info"
22
+	case WarnLevel:
23
+		return "warning"
24
+	case ErrorLevel:
25
+		return "error"
26
+	case FatalLevel:
27
+		return "fatal"
28
+	case PanicLevel:
29
+		return "panic"
30
+	}
31
+
32
+	return "unknown"
33
+}
34
+
35
+// ParseLevel takes a string level and returns the Logrus log level constant.
36
+func ParseLevel(lvl string) (Level, error) {
37
+	switch strings.ToLower(lvl) {
38
+	case "panic":
39
+		return PanicLevel, nil
40
+	case "fatal":
41
+		return FatalLevel, nil
42
+	case "error":
43
+		return ErrorLevel, nil
44
+	case "warn", "warning":
45
+		return WarnLevel, nil
46
+	case "info":
47
+		return InfoLevel, nil
48
+	case "debug":
49
+		return DebugLevel, nil
50
+	}
51
+
52
+	var l Level
53
+	return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
54
+}
55
+
56
+// A constant exposing all logging levels
57
+var AllLevels = []Level{
58
+	PanicLevel,
59
+	FatalLevel,
60
+	ErrorLevel,
61
+	WarnLevel,
62
+	InfoLevel,
63
+	DebugLevel,
64
+}
65
+
66
+// These are the different logging levels. You can set the logging level to log
67
+// on your instance of logger, obtained with `logrus.New()`.
68
+const (
69
+	// PanicLevel level, highest level of severity. Logs and then calls panic with the
70
+	// message passed to Debug, Info, ...
71
+	PanicLevel Level = iota
72
+	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
73
+	// logging level is set to Panic.
74
+	FatalLevel
75
+	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
76
+	// Commonly used for hooks to send errors to an error tracking service.
77
+	ErrorLevel
78
+	// WarnLevel level. Non-critical entries that deserve eyes.
79
+	WarnLevel
80
+	// InfoLevel level. General operational entries about what's going on inside the
81
+	// application.
82
+	InfoLevel
83
+	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
84
+	DebugLevel
85
+)
86
+
87
+// Won't compile if StdLogger can't be realized by a log.Logger
88
+var (
89
+	_ StdLogger = &log.Logger{}
90
+	_ StdLogger = &Entry{}
91
+	_ StdLogger = &Logger{}
92
+)
93
+
94
+// StdLogger is what your logrus-enabled library should take, that way
95
+// it'll accept a stdlib logger and a logrus logger. There's no standard
96
+// interface, this is the closest we get, unfortunately.
97
+type StdLogger interface {
98
+	Print(...interface{})
99
+	Printf(string, ...interface{})
100
+	Println(...interface{})
101
+
102
+	Fatal(...interface{})
103
+	Fatalf(string, ...interface{})
104
+	Fatalln(...interface{})
105
+
106
+	Panic(...interface{})
107
+	Panicf(string, ...interface{})
108
+	Panicln(...interface{})
109
+}
110
+
111
+// The FieldLogger interface generalizes the Entry and Logger types
112
+type FieldLogger interface {
113
+	WithField(key string, value interface{}) *Entry
114
+	WithFields(fields Fields) *Entry
115
+	WithError(err error) *Entry
116
+
117
+	Debugf(format string, args ...interface{})
118
+	Infof(format string, args ...interface{})
119
+	Printf(format string, args ...interface{})
120
+	Warnf(format string, args ...interface{})
121
+	Warningf(format string, args ...interface{})
122
+	Errorf(format string, args ...interface{})
123
+	Fatalf(format string, args ...interface{})
124
+	Panicf(format string, args ...interface{})
125
+
126
+	Debug(args ...interface{})
127
+	Info(args ...interface{})
128
+	Print(args ...interface{})
129
+	Warn(args ...interface{})
130
+	Warning(args ...interface{})
131
+	Error(args ...interface{})
132
+	Fatal(args ...interface{})
133
+	Panic(args ...interface{})
134
+
135
+	Debugln(args ...interface{})
136
+	Infoln(args ...interface{})
137
+	Println(args ...interface{})
138
+	Warnln(args ...interface{})
139
+	Warningln(args ...interface{})
140
+	Errorln(args ...interface{})
141
+	Fatalln(args ...interface{})
142
+	Panicln(args ...interface{})
143
+}

+ 386
- 0
vendor/src/github.com/sirupsen/logrus/logrus_test.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"bytes"
5
+	"encoding/json"
6
+	"strconv"
7
+	"strings"
8
+	"sync"
9
+	"testing"
10
+
11
+	"github.com/stretchr/testify/assert"
12
+)
13
+
14
+func LogAndAssertJSON(t *testing.T, log func(*Logger), assertions func(fields Fields)) {
15
+	var buffer bytes.Buffer
16
+	var fields Fields
17
+
18
+	logger := New()
19
+	logger.Out = &buffer
20
+	logger.Formatter = new(JSONFormatter)
21
+
22
+	log(logger)
23
+
24
+	err := json.Unmarshal(buffer.Bytes(), &fields)
25
+	assert.Nil(t, err)
26
+
27
+	assertions(fields)
28
+}
29
+
30
+func LogAndAssertText(t *testing.T, log func(*Logger), assertions func(fields map[string]string)) {
31
+	var buffer bytes.Buffer
32
+
33
+	logger := New()
34
+	logger.Out = &buffer
35
+	logger.Formatter = &TextFormatter{
36
+		DisableColors: true,
37
+	}
38
+
39
+	log(logger)
40
+
41
+	fields := make(map[string]string)
42
+	for _, kv := range strings.Split(buffer.String(), " ") {
43
+		if !strings.Contains(kv, "=") {
44
+			continue
45
+		}
46
+		kvArr := strings.Split(kv, "=")
47
+		key := strings.TrimSpace(kvArr[0])
48
+		val := kvArr[1]
49
+		if kvArr[1][0] == '"' {
50
+			var err error
51
+			val, err = strconv.Unquote(val)
52
+			assert.NoError(t, err)
53
+		}
54
+		fields[key] = val
55
+	}
56
+	assertions(fields)
57
+}
58
+
59
+func TestPrint(t *testing.T) {
60
+	LogAndAssertJSON(t, func(log *Logger) {
61
+		log.Print("test")
62
+	}, func(fields Fields) {
63
+		assert.Equal(t, fields["msg"], "test")
64
+		assert.Equal(t, fields["level"], "info")
65
+	})
66
+}
67
+
68
+func TestInfo(t *testing.T) {
69
+	LogAndAssertJSON(t, func(log *Logger) {
70
+		log.Info("test")
71
+	}, func(fields Fields) {
72
+		assert.Equal(t, fields["msg"], "test")
73
+		assert.Equal(t, fields["level"], "info")
74
+	})
75
+}
76
+
77
+func TestWarn(t *testing.T) {
78
+	LogAndAssertJSON(t, func(log *Logger) {
79
+		log.Warn("test")
80
+	}, func(fields Fields) {
81
+		assert.Equal(t, fields["msg"], "test")
82
+		assert.Equal(t, fields["level"], "warning")
83
+	})
84
+}
85
+
86
+func TestInfolnShouldAddSpacesBetweenStrings(t *testing.T) {
87
+	LogAndAssertJSON(t, func(log *Logger) {
88
+		log.Infoln("test", "test")
89
+	}, func(fields Fields) {
90
+		assert.Equal(t, fields["msg"], "test test")
91
+	})
92
+}
93
+
94
+func TestInfolnShouldAddSpacesBetweenStringAndNonstring(t *testing.T) {
95
+	LogAndAssertJSON(t, func(log *Logger) {
96
+		log.Infoln("test", 10)
97
+	}, func(fields Fields) {
98
+		assert.Equal(t, fields["msg"], "test 10")
99
+	})
100
+}
101
+
102
+func TestInfolnShouldAddSpacesBetweenTwoNonStrings(t *testing.T) {
103
+	LogAndAssertJSON(t, func(log *Logger) {
104
+		log.Infoln(10, 10)
105
+	}, func(fields Fields) {
106
+		assert.Equal(t, fields["msg"], "10 10")
107
+	})
108
+}
109
+
110
+func TestInfoShouldAddSpacesBetweenTwoNonStrings(t *testing.T) {
111
+	LogAndAssertJSON(t, func(log *Logger) {
112
+		log.Infoln(10, 10)
113
+	}, func(fields Fields) {
114
+		assert.Equal(t, fields["msg"], "10 10")
115
+	})
116
+}
117
+
118
+func TestInfoShouldNotAddSpacesBetweenStringAndNonstring(t *testing.T) {
119
+	LogAndAssertJSON(t, func(log *Logger) {
120
+		log.Info("test", 10)
121
+	}, func(fields Fields) {
122
+		assert.Equal(t, fields["msg"], "test10")
123
+	})
124
+}
125
+
126
+func TestInfoShouldNotAddSpacesBetweenStrings(t *testing.T) {
127
+	LogAndAssertJSON(t, func(log *Logger) {
128
+		log.Info("test", "test")
129
+	}, func(fields Fields) {
130
+		assert.Equal(t, fields["msg"], "testtest")
131
+	})
132
+}
133
+
134
+func TestWithFieldsShouldAllowAssignments(t *testing.T) {
135
+	var buffer bytes.Buffer
136
+	var fields Fields
137
+
138
+	logger := New()
139
+	logger.Out = &buffer
140
+	logger.Formatter = new(JSONFormatter)
141
+
142
+	localLog := logger.WithFields(Fields{
143
+		"key1": "value1",
144
+	})
145
+
146
+	localLog.WithField("key2", "value2").Info("test")
147
+	err := json.Unmarshal(buffer.Bytes(), &fields)
148
+	assert.Nil(t, err)
149
+
150
+	assert.Equal(t, "value2", fields["key2"])
151
+	assert.Equal(t, "value1", fields["key1"])
152
+
153
+	buffer = bytes.Buffer{}
154
+	fields = Fields{}
155
+	localLog.Info("test")
156
+	err = json.Unmarshal(buffer.Bytes(), &fields)
157
+	assert.Nil(t, err)
158
+
159
+	_, ok := fields["key2"]
160
+	assert.Equal(t, false, ok)
161
+	assert.Equal(t, "value1", fields["key1"])
162
+}
163
+
164
+func TestUserSuppliedFieldDoesNotOverwriteDefaults(t *testing.T) {
165
+	LogAndAssertJSON(t, func(log *Logger) {
166
+		log.WithField("msg", "hello").Info("test")
167
+	}, func(fields Fields) {
168
+		assert.Equal(t, fields["msg"], "test")
169
+	})
170
+}
171
+
172
+func TestUserSuppliedMsgFieldHasPrefix(t *testing.T) {
173
+	LogAndAssertJSON(t, func(log *Logger) {
174
+		log.WithField("msg", "hello").Info("test")
175
+	}, func(fields Fields) {
176
+		assert.Equal(t, fields["msg"], "test")
177
+		assert.Equal(t, fields["fields.msg"], "hello")
178
+	})
179
+}
180
+
181
+func TestUserSuppliedTimeFieldHasPrefix(t *testing.T) {
182
+	LogAndAssertJSON(t, func(log *Logger) {
183
+		log.WithField("time", "hello").Info("test")
184
+	}, func(fields Fields) {
185
+		assert.Equal(t, fields["fields.time"], "hello")
186
+	})
187
+}
188
+
189
+func TestUserSuppliedLevelFieldHasPrefix(t *testing.T) {
190
+	LogAndAssertJSON(t, func(log *Logger) {
191
+		log.WithField("level", 1).Info("test")
192
+	}, func(fields Fields) {
193
+		assert.Equal(t, fields["level"], "info")
194
+		assert.Equal(t, fields["fields.level"], 1.0) // JSON has floats only
195
+	})
196
+}
197
+
198
+func TestDefaultFieldsAreNotPrefixed(t *testing.T) {
199
+	LogAndAssertText(t, func(log *Logger) {
200
+		ll := log.WithField("herp", "derp")
201
+		ll.Info("hello")
202
+		ll.Info("bye")
203
+	}, func(fields map[string]string) {
204
+		for _, fieldName := range []string{"fields.level", "fields.time", "fields.msg"} {
205
+			if _, ok := fields[fieldName]; ok {
206
+				t.Fatalf("should not have prefixed %q: %v", fieldName, fields)
207
+			}
208
+		}
209
+	})
210
+}
211
+
212
+func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
213
+
214
+	var buffer bytes.Buffer
215
+	var fields Fields
216
+
217
+	logger := New()
218
+	logger.Out = &buffer
219
+	logger.Formatter = new(JSONFormatter)
220
+
221
+	llog := logger.WithField("context", "eating raw fish")
222
+
223
+	llog.Info("looks delicious")
224
+
225
+	err := json.Unmarshal(buffer.Bytes(), &fields)
226
+	assert.NoError(t, err, "should have decoded first message")
227
+	assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields")
228
+	assert.Equal(t, fields["msg"], "looks delicious")
229
+	assert.Equal(t, fields["context"], "eating raw fish")
230
+
231
+	buffer.Reset()
232
+
233
+	llog.Warn("omg it is!")
234
+
235
+	err = json.Unmarshal(buffer.Bytes(), &fields)
236
+	assert.NoError(t, err, "should have decoded second message")
237
+	assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields")
238
+	assert.Equal(t, fields["msg"], "omg it is!")
239
+	assert.Equal(t, fields["context"], "eating raw fish")
240
+	assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
241
+
242
+}
243
+
244
+func TestConvertLevelToString(t *testing.T) {
245
+	assert.Equal(t, "debug", DebugLevel.String())
246
+	assert.Equal(t, "info", InfoLevel.String())
247
+	assert.Equal(t, "warning", WarnLevel.String())
248
+	assert.Equal(t, "error", ErrorLevel.String())
249
+	assert.Equal(t, "fatal", FatalLevel.String())
250
+	assert.Equal(t, "panic", PanicLevel.String())
251
+}
252
+
253
+func TestParseLevel(t *testing.T) {
254
+	l, err := ParseLevel("panic")
255
+	assert.Nil(t, err)
256
+	assert.Equal(t, PanicLevel, l)
257
+
258
+	l, err = ParseLevel("PANIC")
259
+	assert.Nil(t, err)
260
+	assert.Equal(t, PanicLevel, l)
261
+
262
+	l, err = ParseLevel("fatal")
263
+	assert.Nil(t, err)
264
+	assert.Equal(t, FatalLevel, l)
265
+
266
+	l, err = ParseLevel("FATAL")
267
+	assert.Nil(t, err)
268
+	assert.Equal(t, FatalLevel, l)
269
+
270
+	l, err = ParseLevel("error")
271
+	assert.Nil(t, err)
272
+	assert.Equal(t, ErrorLevel, l)
273
+
274
+	l, err = ParseLevel("ERROR")
275
+	assert.Nil(t, err)
276
+	assert.Equal(t, ErrorLevel, l)
277
+
278
+	l, err = ParseLevel("warn")
279
+	assert.Nil(t, err)
280
+	assert.Equal(t, WarnLevel, l)
281
+
282
+	l, err = ParseLevel("WARN")
283
+	assert.Nil(t, err)
284
+	assert.Equal(t, WarnLevel, l)
285
+
286
+	l, err = ParseLevel("warning")
287
+	assert.Nil(t, err)
288
+	assert.Equal(t, WarnLevel, l)
289
+
290
+	l, err = ParseLevel("WARNING")
291
+	assert.Nil(t, err)
292
+	assert.Equal(t, WarnLevel, l)
293
+
294
+	l, err = ParseLevel("info")
295
+	assert.Nil(t, err)
296
+	assert.Equal(t, InfoLevel, l)
297
+
298
+	l, err = ParseLevel("INFO")
299
+	assert.Nil(t, err)
300
+	assert.Equal(t, InfoLevel, l)
301
+
302
+	l, err = ParseLevel("debug")
303
+	assert.Nil(t, err)
304
+	assert.Equal(t, DebugLevel, l)
305
+
306
+	l, err = ParseLevel("DEBUG")
307
+	assert.Nil(t, err)
308
+	assert.Equal(t, DebugLevel, l)
309
+
310
+	l, err = ParseLevel("invalid")
311
+	assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
312
+}
313
+
314
+func TestGetSetLevelRace(t *testing.T) {
315
+	wg := sync.WaitGroup{}
316
+	for i := 0; i < 100; i++ {
317
+		wg.Add(1)
318
+		go func(i int) {
319
+			defer wg.Done()
320
+			if i%2 == 0 {
321
+				SetLevel(InfoLevel)
322
+			} else {
323
+				GetLevel()
324
+			}
325
+		}(i)
326
+
327
+	}
328
+	wg.Wait()
329
+}
330
+
331
+func TestLoggingRace(t *testing.T) {
332
+	logger := New()
333
+
334
+	var wg sync.WaitGroup
335
+	wg.Add(100)
336
+
337
+	for i := 0; i < 100; i++ {
338
+		go func() {
339
+			logger.Info("info")
340
+			wg.Done()
341
+		}()
342
+	}
343
+	wg.Wait()
344
+}
345
+
346
+// Compile test
347
+func TestLogrusInterface(t *testing.T) {
348
+	var buffer bytes.Buffer
349
+	fn := func(l FieldLogger) {
350
+		b := l.WithField("key", "value")
351
+		b.Debug("Test")
352
+	}
353
+	// test logger
354
+	logger := New()
355
+	logger.Out = &buffer
356
+	fn(logger)
357
+
358
+	// test Entry
359
+	e := logger.WithField("another", "value")
360
+	fn(e)
361
+}
362
+
363
+// Implements io.Writer using channels for synchronization, so we can wait on
364
+// the Entry.Writer goroutine to write in a non-racey way. This does assume that
365
+// there is a single call to Logger.Out for each message.
366
+type channelWriter chan []byte
367
+
368
+func (cw channelWriter) Write(p []byte) (int, error) {
369
+	cw <- p
370
+	return len(p), nil
371
+}
372
+
373
+func TestEntryWriter(t *testing.T) {
374
+	cw := channelWriter(make(chan []byte, 1))
375
+	log := New()
376
+	log.Out = cw
377
+	log.Formatter = new(JSONFormatter)
378
+	log.WithField("foo", "bar").WriterLevel(WarnLevel).Write([]byte("hello\n"))
379
+
380
+	bs := <-cw
381
+	var fields Fields
382
+	err := json.Unmarshal(bs, &fields)
383
+	assert.Nil(t, err)
384
+	assert.Equal(t, fields["foo"], "bar")
385
+	assert.Equal(t, fields["level"], "warning")
386
+}

+ 10
- 0
vendor/src/github.com/sirupsen/logrus/terminal_bsd.go Bestand weergeven

1
+// +build darwin freebsd openbsd netbsd dragonfly
2
+// +build !appengine
3
+
4
+package logrus
5
+
6
+import "golang.org/x/sys/unix"
7
+
8
+const ioctlReadTermios = unix.TIOCGETA
9
+
10
+type Termios unix.Termios

+ 14
- 0
vendor/src/github.com/sirupsen/logrus/terminal_linux.go Bestand weergeven

1
+// Based on ssh/terminal:
2
+// Copyright 2013 The Go Authors. All rights reserved.
3
+// Use of this source code is governed by a BSD-style
4
+// license that can be found in the LICENSE file.
5
+
6
+// +build !appengine
7
+
8
+package logrus
9
+
10
+import "golang.org/x/sys/unix"
11
+
12
+const ioctlReadTermios = unix.TCGETS
13
+
14
+type Termios unix.Termios

+ 191
- 0
vendor/src/github.com/sirupsen/logrus/text_formatter.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"bytes"
5
+	"fmt"
6
+	"io"
7
+	"os"
8
+	"sort"
9
+	"strings"
10
+	"sync"
11
+	"time"
12
+
13
+	"golang.org/x/crypto/ssh/terminal"
14
+)
15
+
16
+const (
17
+	nocolor = 0
18
+	red     = 31
19
+	green   = 32
20
+	yellow  = 33
21
+	blue    = 36
22
+	gray    = 37
23
+)
24
+
25
+var (
26
+	baseTimestamp time.Time
27
+)
28
+
29
+func init() {
30
+	baseTimestamp = time.Now()
31
+}
32
+
33
+// TextFormatter formats logs into text
34
+type TextFormatter struct {
35
+	// Set to true to bypass checking for a TTY before outputting colors.
36
+	ForceColors bool
37
+
38
+	// Force disabling colors.
39
+	DisableColors bool
40
+
41
+	// Disable timestamp logging. useful when output is redirected to logging
42
+	// system that already adds timestamps.
43
+	DisableTimestamp bool
44
+
45
+	// Enable logging the full timestamp when a TTY is attached instead of just
46
+	// the time passed since beginning of execution.
47
+	FullTimestamp bool
48
+
49
+	// TimestampFormat to use for display when a full timestamp is printed
50
+	TimestampFormat string
51
+
52
+	// The fields are sorted by default for a consistent output. For applications
53
+	// that log extremely frequently and don't use the JSON formatter this may not
54
+	// be desired.
55
+	DisableSorting bool
56
+
57
+	// QuoteEmptyFields will wrap empty fields in quotes if true
58
+	QuoteEmptyFields bool
59
+
60
+	// Whether the logger's out is to a terminal
61
+	isTerminal bool
62
+
63
+	sync.Once
64
+}
65
+
66
+func (f *TextFormatter) init(entry *Entry) {
67
+	if entry.Logger != nil {
68
+		f.isTerminal = f.checkIfTerminal(entry.Logger.Out)
69
+	}
70
+}
71
+
72
+func (f *TextFormatter) checkIfTerminal(w io.Writer) bool {
73
+	switch v := w.(type) {
74
+	case *os.File:
75
+		return terminal.IsTerminal(int(v.Fd()))
76
+	default:
77
+		return false
78
+	}
79
+}
80
+
81
+// Format renders a single log entry
82
+func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
83
+	var b *bytes.Buffer
84
+	keys := make([]string, 0, len(entry.Data))
85
+	for k := range entry.Data {
86
+		keys = append(keys, k)
87
+	}
88
+
89
+	if !f.DisableSorting {
90
+		sort.Strings(keys)
91
+	}
92
+	if entry.Buffer != nil {
93
+		b = entry.Buffer
94
+	} else {
95
+		b = &bytes.Buffer{}
96
+	}
97
+
98
+	prefixFieldClashes(entry.Data)
99
+
100
+	f.Do(func() { f.init(entry) })
101
+
102
+	isColored := (f.ForceColors || f.isTerminal) && !f.DisableColors
103
+
104
+	timestampFormat := f.TimestampFormat
105
+	if timestampFormat == "" {
106
+		timestampFormat = defaultTimestampFormat
107
+	}
108
+	if isColored {
109
+		f.printColored(b, entry, keys, timestampFormat)
110
+	} else {
111
+		if !f.DisableTimestamp {
112
+			f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat))
113
+		}
114
+		f.appendKeyValue(b, "level", entry.Level.String())
115
+		if entry.Message != "" {
116
+			f.appendKeyValue(b, "msg", entry.Message)
117
+		}
118
+		for _, key := range keys {
119
+			f.appendKeyValue(b, key, entry.Data[key])
120
+		}
121
+	}
122
+
123
+	b.WriteByte('\n')
124
+	return b.Bytes(), nil
125
+}
126
+
127
+func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, timestampFormat string) {
128
+	var levelColor int
129
+	switch entry.Level {
130
+	case DebugLevel:
131
+		levelColor = gray
132
+	case WarnLevel:
133
+		levelColor = yellow
134
+	case ErrorLevel, FatalLevel, PanicLevel:
135
+		levelColor = red
136
+	default:
137
+		levelColor = blue
138
+	}
139
+
140
+	levelText := strings.ToUpper(entry.Level.String())[0:4]
141
+
142
+	if f.DisableTimestamp {
143
+		fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message)
144
+	} else if !f.FullTimestamp {
145
+		fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message)
146
+	} else {
147
+		fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message)
148
+	}
149
+	for _, k := range keys {
150
+		v := entry.Data[k]
151
+		fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k)
152
+		f.appendValue(b, v)
153
+	}
154
+}
155
+
156
+func (f *TextFormatter) needsQuoting(text string) bool {
157
+	if f.QuoteEmptyFields && len(text) == 0 {
158
+		return true
159
+	}
160
+	for _, ch := range text {
161
+		if !((ch >= 'a' && ch <= 'z') ||
162
+			(ch >= 'A' && ch <= 'Z') ||
163
+			(ch >= '0' && ch <= '9') ||
164
+			ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') {
165
+			return true
166
+		}
167
+	}
168
+	return false
169
+}
170
+
171
+func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {
172
+	if b.Len() > 0 {
173
+		b.WriteByte(' ')
174
+	}
175
+	b.WriteString(key)
176
+	b.WriteByte('=')
177
+	f.appendValue(b, value)
178
+}
179
+
180
+func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
181
+	stringVal, ok := value.(string)
182
+	if !ok {
183
+		stringVal = fmt.Sprint(value)
184
+	}
185
+
186
+	if !f.needsQuoting(stringVal) {
187
+		b.WriteString(stringVal)
188
+	} else {
189
+		b.WriteString(fmt.Sprintf("%q", stringVal))
190
+	}
191
+}

+ 141
- 0
vendor/src/github.com/sirupsen/logrus/text_formatter_test.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"bytes"
5
+	"errors"
6
+	"fmt"
7
+	"strings"
8
+	"testing"
9
+	"time"
10
+)
11
+
12
+func TestFormatting(t *testing.T) {
13
+	tf := &TextFormatter{DisableColors: true}
14
+
15
+	testCases := []struct {
16
+		value    string
17
+		expected string
18
+	}{
19
+		{`foo`, "time=\"0001-01-01T00:00:00Z\" level=panic test=foo\n"},
20
+	}
21
+
22
+	for _, tc := range testCases {
23
+		b, _ := tf.Format(WithField("test", tc.value))
24
+
25
+		if string(b) != tc.expected {
26
+			t.Errorf("formatting expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected)
27
+		}
28
+	}
29
+}
30
+
31
+func TestQuoting(t *testing.T) {
32
+	tf := &TextFormatter{DisableColors: true}
33
+
34
+	checkQuoting := func(q bool, value interface{}) {
35
+		b, _ := tf.Format(WithField("test", value))
36
+		idx := bytes.Index(b, ([]byte)("test="))
37
+		cont := bytes.Contains(b[idx+5:], []byte("\""))
38
+		if cont != q {
39
+			if q {
40
+				t.Errorf("quoting expected for: %#v", value)
41
+			} else {
42
+				t.Errorf("quoting not expected for: %#v", value)
43
+			}
44
+		}
45
+	}
46
+
47
+	checkQuoting(false, "")
48
+	checkQuoting(false, "abcd")
49
+	checkQuoting(false, "v1.0")
50
+	checkQuoting(false, "1234567890")
51
+	checkQuoting(false, "/foobar")
52
+	checkQuoting(false, "foo_bar")
53
+	checkQuoting(false, "foo@bar")
54
+	checkQuoting(false, "foobar^")
55
+	checkQuoting(false, "+/-_^@f.oobar")
56
+	checkQuoting(true, "foobar$")
57
+	checkQuoting(true, "&foobar")
58
+	checkQuoting(true, "x y")
59
+	checkQuoting(true, "x,y")
60
+	checkQuoting(false, errors.New("invalid"))
61
+	checkQuoting(true, errors.New("invalid argument"))
62
+
63
+	// Test for quoting empty fields.
64
+	tf.QuoteEmptyFields = true
65
+	checkQuoting(true, "")
66
+	checkQuoting(false, "abcd")
67
+	checkQuoting(true, errors.New("invalid argument"))
68
+}
69
+
70
+func TestEscaping(t *testing.T) {
71
+	tf := &TextFormatter{DisableColors: true}
72
+
73
+	testCases := []struct {
74
+		value    string
75
+		expected string
76
+	}{
77
+		{`ba"r`, `ba\"r`},
78
+		{`ba'r`, `ba'r`},
79
+	}
80
+
81
+	for _, tc := range testCases {
82
+		b, _ := tf.Format(WithField("test", tc.value))
83
+		if !bytes.Contains(b, []byte(tc.expected)) {
84
+			t.Errorf("escaping expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected)
85
+		}
86
+	}
87
+}
88
+
89
+func TestEscaping_Interface(t *testing.T) {
90
+	tf := &TextFormatter{DisableColors: true}
91
+
92
+	ts := time.Now()
93
+
94
+	testCases := []struct {
95
+		value    interface{}
96
+		expected string
97
+	}{
98
+		{ts, fmt.Sprintf("\"%s\"", ts.String())},
99
+		{errors.New("error: something went wrong"), "\"error: something went wrong\""},
100
+	}
101
+
102
+	for _, tc := range testCases {
103
+		b, _ := tf.Format(WithField("test", tc.value))
104
+		if !bytes.Contains(b, []byte(tc.expected)) {
105
+			t.Errorf("escaping expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected)
106
+		}
107
+	}
108
+}
109
+
110
+func TestTimestampFormat(t *testing.T) {
111
+	checkTimeStr := func(format string) {
112
+		customFormatter := &TextFormatter{DisableColors: true, TimestampFormat: format}
113
+		customStr, _ := customFormatter.Format(WithField("test", "test"))
114
+		timeStart := bytes.Index(customStr, ([]byte)("time="))
115
+		timeEnd := bytes.Index(customStr, ([]byte)("level="))
116
+		timeStr := customStr[timeStart+5+len("\"") : timeEnd-1-len("\"")]
117
+		if format == "" {
118
+			format = time.RFC3339
119
+		}
120
+		_, e := time.Parse(format, (string)(timeStr))
121
+		if e != nil {
122
+			t.Errorf("time string \"%s\" did not match provided time format \"%s\": %s", timeStr, format, e)
123
+		}
124
+	}
125
+
126
+	checkTimeStr("2006-01-02T15:04:05.000000000Z07:00")
127
+	checkTimeStr("Mon Jan _2 15:04:05 2006")
128
+	checkTimeStr("")
129
+}
130
+
131
+func TestDisableTimestampWithColoredOutput(t *testing.T) {
132
+	tf := &TextFormatter{DisableTimestamp: true, ForceColors: true}
133
+
134
+	b, _ := tf.Format(WithField("test", "test"))
135
+	if strings.Contains(string(b), "[0000]") {
136
+		t.Error("timestamp not expected when DisableTimestamp is true")
137
+	}
138
+}
139
+
140
+// TODO add tests for sorting etc., this requires a parser for the text
141
+// formatter output.

+ 62
- 0
vendor/src/github.com/sirupsen/logrus/writer.go Bestand weergeven

1
+package logrus
2
+
3
+import (
4
+	"bufio"
5
+	"io"
6
+	"runtime"
7
+)
8
+
9
+func (logger *Logger) Writer() *io.PipeWriter {
10
+	return logger.WriterLevel(InfoLevel)
11
+}
12
+
13
+func (logger *Logger) WriterLevel(level Level) *io.PipeWriter {
14
+	return NewEntry(logger).WriterLevel(level)
15
+}
16
+
17
+func (entry *Entry) Writer() *io.PipeWriter {
18
+	return entry.WriterLevel(InfoLevel)
19
+}
20
+
21
+func (entry *Entry) WriterLevel(level Level) *io.PipeWriter {
22
+	reader, writer := io.Pipe()
23
+
24
+	var printFunc func(args ...interface{})
25
+
26
+	switch level {
27
+	case DebugLevel:
28
+		printFunc = entry.Debug
29
+	case InfoLevel:
30
+		printFunc = entry.Info
31
+	case WarnLevel:
32
+		printFunc = entry.Warn
33
+	case ErrorLevel:
34
+		printFunc = entry.Error
35
+	case FatalLevel:
36
+		printFunc = entry.Fatal
37
+	case PanicLevel:
38
+		printFunc = entry.Panic
39
+	default:
40
+		printFunc = entry.Print
41
+	}
42
+
43
+	go entry.writerScanner(reader, printFunc)
44
+	runtime.SetFinalizer(writer, writerFinalizer)
45
+
46
+	return writer
47
+}
48
+
49
+func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) {
50
+	scanner := bufio.NewScanner(reader)
51
+	for scanner.Scan() {
52
+		printFunc(scanner.Text())
53
+	}
54
+	if err := scanner.Err(); err != nil {
55
+		entry.Errorf("Error while reading from Writer: %s", err)
56
+	}
57
+	reader.Close()
58
+}
59
+
60
+func writerFinalizer(writer *io.PipeWriter) {
61
+	writer.Close()
62
+}