Skip to content

Commit

Permalink
fixed race
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Jul 5, 2018
1 parent e4e6685 commit 73a22ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_install:
- mysql -e 'CREATE DATABASE myapp_test;'
- go get -t -v ./...
script:
- go test -coverprofile=coverage.txt -covermode=atomic
- go test -race -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
7 changes: 5 additions & 2 deletions hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ var defaultOptions = options{
},
}

// FilterHandle a filter handler
type FilterHandle func(*logrus.Entry) *logrus.Entry

type options struct {
maxQueues int
maxWorkers int
extra map[string]interface{}
exec Execer
filter func(*logrus.Entry) *logrus.Entry
filter FilterHandle
levels []logrus.Level
out io.Writer
}
Expand Down Expand Up @@ -60,7 +63,7 @@ func SetExec(exec Execer) Option {
}

// SetFilter set the entry filter
func SetFilter(filter func(*logrus.Entry) *logrus.Entry) Option {
func SetFilter(filter FilterHandle) Option {
return func(o *options) {
o.filter = filter
}
Expand Down
12 changes: 10 additions & 2 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ type job struct {
entry *logrus.Entry
exec Execer
extra map[string]interface{}
filter func(*logrus.Entry) *logrus.Entry
filter FilterHandle
}

func (j *job) Reset(entry *logrus.Entry) {
func (j *job) Reset(e *logrus.Entry) {
entry := logrus.NewEntry(e.Logger)
entry.Data = make(logrus.Fields)
entry.Time = e.Time
entry.Level = e.Level
entry.Message = e.Message
for k, v := range e.Data {
entry.Data[k] = v
}
j.entry = entry
}

Expand Down

0 comments on commit 73a22ea

Please sign in to comment.