Skip to content

Commit

Permalink
Merge pull request #4 from nrfta/feat/create-error-and-log-it
Browse files Browse the repository at this point in the history
add log new error methods; convert Fields to []Field
  • Loading branch information
strobus authored Jan 15, 2021
2 parents 680fa56 + 1c5406d commit 81601eb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ jobs:
with:
go-version: 1.14.x

- name: Set GOPATH
# temporary fix
# see https://github.com/actions/setup-go/issues/14
run: |
echo "##[set-env name=GOPATH;]$(dirname $GITHUB_WORKSPACE)"
echo "##[add-path]$(dirname $GITHUB_WORKSPACE)/bin"
shell: bash

- name: Install Dependencies
run: go mod download

Expand Down
7 changes: 7 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func MakeField(name string, value interface{}) Field {
return Field{name, value}
}

func FieldsToFieldsArray(fields Fields) (arr []Field) {
for name, value := range fields {
arr = append(arr, MakeField(name, value))
}
return
}

func makeFieldStackItem(fields []Field) *fieldStackItem {
return &fieldStackItem{fields}
}
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
Expand Down Expand Up @@ -64,7 +66,9 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
Expand Down
22 changes: 22 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package log

import (
"context"
"errors"
"fmt"
"io"
"net/http"
"time"
Expand Down Expand Up @@ -145,6 +147,26 @@ func ErrorWithFieldsf(fields Fields, message string, args ...interface{}) {
logger.WithFields(logrus.Fields(fields)).Errorf(message, args...)
}

func NewError(args ...interface{}) error {
Error(args...)
return errors.New(fmt.Sprint(args...))
}

func NewErrorf(message string, args ...interface{}) error {
Errorf(message, args...)
return fmt.Errorf(message, args...)
}

func NewErrorWithFields(fields Fields, args ...interface{}) error {
ErrorWithFields(fields, args...)
return errors.New(fmt.Sprint(args...))
}

func NewErrorWithFieldsf(fields Fields, message string, args ...interface{}) error {
ErrorWithFieldsf(fields, message, args...)
return fmt.Errorf(message, args...)
}

func Warn(args ...interface{}) {
logger.Warn(args...)
}
Expand Down

0 comments on commit 81601eb

Please sign in to comment.