diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/go-hclog/stdlog.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/hashicorp/go-hclog/stdlog.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-hclog/stdlog.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-hclog/stdlog.go b/vendor/github.com/hashicorp/go-hclog/stdlog.go new file mode 100644 index 0000000..2bb927f --- /dev/null +++ b/vendor/github.com/hashicorp/go-hclog/stdlog.go | |||
@@ -0,0 +1,62 @@ | |||
1 | package hclog | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "strings" | ||
6 | ) | ||
7 | |||
8 | // Provides a io.Writer to shim the data out of *log.Logger | ||
9 | // and back into our Logger. This is basically the only way to | ||
10 | // build upon *log.Logger. | ||
11 | type stdlogAdapter struct { | ||
12 | hl Logger | ||
13 | inferLevels bool | ||
14 | } | ||
15 | |||
16 | // Take the data, infer the levels if configured, and send it through | ||
17 | // a regular Logger | ||
18 | func (s *stdlogAdapter) Write(data []byte) (int, error) { | ||
19 | str := string(bytes.TrimRight(data, " \t\n")) | ||
20 | |||
21 | if s.inferLevels { | ||
22 | level, str := s.pickLevel(str) | ||
23 | switch level { | ||
24 | case Trace: | ||
25 | s.hl.Trace(str) | ||
26 | case Debug: | ||
27 | s.hl.Debug(str) | ||
28 | case Info: | ||
29 | s.hl.Info(str) | ||
30 | case Warn: | ||
31 | s.hl.Warn(str) | ||
32 | case Error: | ||
33 | s.hl.Error(str) | ||
34 | default: | ||
35 | s.hl.Info(str) | ||
36 | } | ||
37 | } else { | ||
38 | s.hl.Info(str) | ||
39 | } | ||
40 | |||
41 | return len(data), nil | ||
42 | } | ||
43 | |||
44 | // Detect, based on conventions, what log level this is | ||
45 | func (s *stdlogAdapter) pickLevel(str string) (Level, string) { | ||
46 | switch { | ||
47 | case strings.HasPrefix(str, "[DEBUG]"): | ||
48 | return Debug, strings.TrimSpace(str[7:]) | ||
49 | case strings.HasPrefix(str, "[TRACE]"): | ||
50 | return Trace, strings.TrimSpace(str[7:]) | ||
51 | case strings.HasPrefix(str, "[INFO]"): | ||
52 | return Info, strings.TrimSpace(str[6:]) | ||
53 | case strings.HasPrefix(str, "[WARN]"): | ||
54 | return Warn, strings.TrimSpace(str[7:]) | ||
55 | case strings.HasPrefix(str, "[ERROR]"): | ||
56 | return Error, strings.TrimSpace(str[7:]) | ||
57 | case strings.HasPrefix(str, "[ERR]"): | ||
58 | return Error, strings.TrimSpace(str[5:]) | ||
59 | default: | ||
60 | return Info, str | ||
61 | } | ||
62 | } | ||