Skip to content

Commit

Permalink
Merge pull request inconshreveable#75 from NathanBaulch/master
Browse files Browse the repository at this point in the history
Expose logger's current handler
  • Loading branch information
inconshreveable committed Apr 1, 2016
2 parents 210d6fd + 94e71a7 commit 57a084d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion handler_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ type swapHandler struct {
}

func (h *swapHandler) Log(r *Record) error {
return (*(*Handler)(atomic.LoadPointer(&h.handler))).Log(r)
return h.Get().Log(r)
}

func (h *swapHandler) Get() Handler {
return *(*Handler)(atomic.LoadPointer(&h.handler))
}

func (h *swapHandler) Swap(newHandler Handler) {
Expand Down
7 changes: 7 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type Logger interface {
// New returns a new Logger that has this logger's context plus the given context
New(ctx ...interface{}) Logger

// GetHandler gets the handler associated with the logger.
GetHandler() Handler

// SetHandler updates the logger to write records to the specified handler.
SetHandler(h Handler)

Expand Down Expand Up @@ -145,6 +148,10 @@ func (l *logger) Crit(msg string, ctx ...interface{}) {
l.write(msg, LvlCrit, ctx)
}

func (l *logger) GetHandler() Handler {
return l.h.Get()
}

func (l *logger) SetHandler(h Handler) {
l.h.Swap(h)
}
Expand Down

0 comments on commit 57a084d

Please sign in to comment.