Skip to content

Commit

Permalink
Merge pull request #33 from Grindlemire/logrus_support
Browse files Browse the repository at this point in the history
Logrus support and Versioning for Death
  • Loading branch information
vrecan authored Mar 27, 2018
2 parents a6a7840 + 5c009c4 commit 8f7e3ee
Show file tree
Hide file tree
Showing 276 changed files with 155,406 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.6
- "1.10"

install:
- go get golang.org/x/tools/cmd/cover
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@

## Get The Library

Use gopkg.in to import death based on your logger.

Version | Go Get URL | source | doc | Notes |
--------|------------|--------|-----|-------|
2.x | [gopkg.in/vrecan/death.v2](https://gopkg.in/vrecan/death.v2)| [source]() | [doc]() | This supports loggers who _do not_ return an error from their `Error` and `Warn` functions like [logrus](https://github.com/sirupsen/logrus)
1.x | [gopkg.in/vrecan/death.v1](https://gopkg.in/vrecan/death.v1)| [souce](https://github.com/vrecan/death/tree/v1.0) | [doc](https://godoc.org/gopkg.in/vrecan/death.v1) | This supports loggers who _do_ return an error from their `Error` and `Warn` functions like [seelog](https://github.com/cihub/seelog)



Example
```bash
go get github.com/vrecan/death
go get gopkg.in/vrecan/death.v2
```
## Use The Library

Expand Down
14 changes: 8 additions & 6 deletions death.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

LOG "github.com/cihub/seelog"
log "github.com/sirupsen/logrus"
)

//Death manages the death of your application.
Expand All @@ -24,10 +24,10 @@ type Death struct {

//Logger interface to log.
type Logger interface {
Error(v ...interface{}) error
Error(v ...interface{})
Debug(v ...interface{})
Info(v ...interface{})
Warn(v ...interface{}) error
Warn(v ...interface{})
}

//closer is a wrapper to the struct we are going to close with metadata
Expand All @@ -45,21 +45,23 @@ func NewDeath(signals ...os.Signal) (death *Death) {
sigChannel: make(chan os.Signal, 1),
callChannel: make(chan struct{}, 1),
wg: &sync.WaitGroup{},
log: LOG.Current}
log: log.StandardLogger()}
signal.Notify(death.sigChannel, signals...)
death.wg.Add(1)
go death.listenForSignal()
return death
}

//SetTimeout Overrides the time death is willing to wait for a objects to be closed.
func (d *Death) SetTimeout(t time.Duration) {
func (d *Death) SetTimeout(t time.Duration) *Death {
d.timeout = t
return d
}

//SetLogger Overrides the default logger (seelog)
func (d *Death) SetLogger(l Logger) {
func (d *Death) SetLogger(l Logger) *Death {
d.log = l
return d
}

//WaitForDeath wait for signal and then kill all items that need to die.
Expand Down
6 changes: 2 additions & 4 deletions death_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,16 @@ func (l *MockLogger) Debug(v ...interface{}) {
}
}

func (l *MockLogger) Error(v ...interface{}) error {
func (l *MockLogger) Error(v ...interface{}) {
for _, log := range v {
l.Logs = append(l.Logs, log)
}
return nil
}

func (l *MockLogger) Warn(v ...interface{}) error {
func (l *MockLogger) Warn(v ...interface{}) {
for _, log := range v {
l.Logs = append(l.Logs, log)
}
return nil
}

type neverClose struct {
Expand Down
118 changes: 118 additions & 0 deletions vendor/github.com/sirupsen/logrus/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/sirupsen/logrus/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8f7e3ee

Please sign in to comment.