Update logging for logrus

This commit is contained in:
Charlie Drage
2017-01-18 09:23:52 -05:00
parent 5837d0ad6e
commit c39e9b3cb0
146 changed files with 31301 additions and 4183 deletions
+9 -10
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -158,16 +158,16 @@ func dec(p *Properties, key string, def *string, opts map[string]string, v refle
// keydef returns the property key and the default value based on the
// name of the struct field and the options in the tag.
keydef := func(f reflect.StructField) (string, *string, map[string]string) {
key, opts := parseTag(f.Tag.Get("properties"))
_key, _opts := parseTag(f.Tag.Get("properties"))
var def *string
if d, ok := opts["default"]; ok {
def = &d
var _def *string
if d, ok := _opts["default"]; ok {
_def = &d
}
if key != "" {
return key, def, opts
if _key != "" {
return _key, _def, _opts
}
return f.Name, def, opts
return f.Name, _def, _opts
}
switch {
@@ -223,7 +223,7 @@ func dec(p *Properties, key string, def *string, opts map[string]string, v refle
case isMap(t):
valT := t.Elem()
m := reflect.MakeMap(t)
for postfix, _ := range p.FilterStripPrefix(key + ".").m {
for postfix := range p.FilterStripPrefix(key + ".").m {
pp := strings.SplitN(postfix, ".", 2)
mk, mv := pp[0], reflect.New(valT)
if err := dec(p, key+"."+mk, nil, nil, mv); err != nil {
@@ -274,7 +274,6 @@ func isArray(t reflect.Type) bool { return t.Kind() == reflect.Array || t.Kin
func isBool(t reflect.Type) bool { return t.Kind() == reflect.Bool }
func isDuration(t reflect.Type) bool { return t == reflect.TypeOf(time.Second) }
func isMap(t reflect.Type) bool { return t.Kind() == reflect.Map }
func isNumeric(t reflect.Type) bool { return isInt(t) || isUint(t) || isFloat(t) }
func isPtr(t reflect.Type) bool { return t.Kind() == reflect.Ptr }
func isString(t reflect.Type) bool { return t.Kind() == reflect.String }
func isStruct(t reflect.Type) bool { return t.Kind() == reflect.Struct }
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+10 -11
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
@@ -72,7 +72,7 @@ type lexer struct {
// next returns the next rune in the input.
func (l *lexer) next() rune {
if int(l.pos) >= len(l.input) {
if l.pos >= len(l.input) {
l.width = 0
return eof
}
@@ -96,8 +96,8 @@ func (l *lexer) backup() {
// emit passes an item back to the client.
func (l *lexer) emit(t itemType) {
item := item{t, l.start, string(l.runes)}
l.items <- item
i := item{t, l.start, string(l.runes)}
l.items <- i
l.start = l.pos
l.runes = l.runes[:0]
}
@@ -114,7 +114,7 @@ func (l *lexer) appendRune(r rune) {
// accept consumes the next rune if it's from the valid set.
func (l *lexer) accept(valid string) bool {
if strings.IndexRune(valid, l.next()) >= 0 {
if strings.ContainsRune(valid, l.next()) {
return true
}
l.backup()
@@ -123,7 +123,7 @@ func (l *lexer) accept(valid string) bool {
// acceptRun consumes a run of runes from the valid set.
func (l *lexer) acceptRun(valid string) {
for strings.IndexRune(valid, l.next()) >= 0 {
for strings.ContainsRune(valid, l.next()) {
}
l.backup()
}
@@ -156,9 +156,9 @@ func (l *lexer) errorf(format string, args ...interface{}) stateFn {
// nextItem returns the next item from the input.
func (l *lexer) nextItem() item {
item := <-l.items
l.lastPos = item.pos
return item
i := <-l.items
l.lastPos = i.pos
return i
}
// lex creates a new scanner for the input string.
@@ -279,8 +279,7 @@ func lexValue(l *lexer) stateFn {
for {
switch r := l.next(); {
case isEscape(r):
r := l.peek()
if isEOL(r) {
if isEOL(l.peek()) {
l.next()
l.acceptRun(whitespace)
} else {
+5 -3
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -98,7 +98,7 @@ func MustLoadURL(url string) *Properties {
return must(LoadURL(url))
}
// MustLoadFiles reads the content of multiple URLs in the given order into a
// MustLoadURLs reads the content of multiple URLs in the given order into a
// Properties struct and panics on error. If 'ignoreMissing' is true then a 404
// status code will not be reported as error.
func MustLoadURLs(urls []string, ignoreMissing bool) *Properties {
@@ -172,10 +172,12 @@ func loadURL(url string, ignoreMissing bool) (*Properties, error) {
return nil, fmt.Errorf("properties: %s returned %d", url, resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, fmt.Errorf("properties: %s error reading response. %s", url, err)
}
if err = resp.Body.Close(); err != nil {
return nil, fmt.Errorf("properties: %s error reading response. %s", url, err)
}
ct := resp.Header.Get("Content-Type")
var enc Encoding
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+11 -4
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -28,8 +28,10 @@ type ErrorHandlerFunc func(error)
// functions. The default is LogFatalHandler.
var ErrorHandler ErrorHandlerFunc = LogFatalHandler
// LogHandlerFunc defines the function prototype for logging errors.
type LogHandlerFunc func(fmt string, args ...interface{})
// LogPrintf defines a log handler which uses log.Printf.
var LogPrintf LogHandlerFunc = log.Printf
// LogFatalHandler handles the error by logging a fatal error and exiting.
@@ -444,6 +446,8 @@ func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties {
pp := NewProperties()
for _, k := range p.k {
if re.MatchString(k) {
// TODO(fs): we are ignoring the error which flags a circular reference.
// TODO(fs): since we are just copying a subset of keys this cannot happen (fingers crossed)
pp.Set(k, p.m[k])
}
}
@@ -456,6 +460,8 @@ func (p *Properties) FilterPrefix(prefix string) *Properties {
pp := NewProperties()
for _, k := range p.k {
if strings.HasPrefix(k, prefix) {
// TODO(fs): we are ignoring the error which flags a circular reference.
// TODO(fs): since we are just copying a subset of keys this cannot happen (fingers crossed)
pp.Set(k, p.m[k])
}
}
@@ -469,6 +475,9 @@ func (p *Properties) FilterStripPrefix(prefix string) *Properties {
n := len(prefix)
for _, k := range p.k {
if len(k) > len(prefix) && strings.HasPrefix(k, prefix) {
// TODO(fs): we are ignoring the error which flags a circular reference.
// TODO(fs): since we are modifying keys I am not entirely sure whether we can create a circular reference
// TODO(fs): this function should probably return an error but the signature is fixed
pp.Set(k[n:], p.m[k])
}
}
@@ -483,9 +492,7 @@ func (p *Properties) Len() int {
// Keys returns all keys in the same order as in the input.
func (p *Properties) Keys() []string {
keys := make([]string, len(p.k))
for i, k := range p.k {
keys[i] = k
}
copy(keys, p.k)
return keys
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2016 Frank Schroeder. All rights reserved.
// Copyright 2017 Frank Schroeder. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.