Skip to content

Commit

Permalink
Export the Hook type
Browse files Browse the repository at this point in the history
In order for users to implement their own hooks, they need access to the
Hook type.
  • Loading branch information
Akshay Shah committed Aug 1, 2016
1 parent 951646b commit fd9cb2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions hook.go
Expand Up @@ -35,20 +35,22 @@ var (
_callerSkip = 3
)

// A hook is executed each time the logger writes an Entry. It can modify the
// A Hook is executed each time the logger writes an Entry. It can modify the
// entry, but must not retain references to the entry or any of its
// contents. Returned errors are written to the logger's error output.
type hook func(*Entry) error
//
// Hooks implement the Option interface.
type Hook func(*Entry) error

// apply implements the Option interface.
func (h hook) apply(m *Meta) {
func (h Hook) apply(m *Meta) {
m.Hooks = append(m.Hooks, h)
}

// AddCaller configures the Logger to annotate each message with the filename
// and line number of zap's caller.
func AddCaller() Option {
return hook(func(e *Entry) error {
return Hook(func(e *Entry) error {
if e == nil {
return errHookNilEntry
}
Expand Down Expand Up @@ -78,7 +80,7 @@ func AddCaller() Option {
// or above a given level. Keep in mind that this is (relatively speaking) quite
// expensive.
func AddStacks(lvl Level) Option {
return hook(func(e *Entry) error {
return Hook(func(e *Entry) error {
if e == nil {
return errHookNilEntry
}
Expand Down
6 changes: 3 additions & 3 deletions hook_test.go
Expand Up @@ -72,10 +72,10 @@ func TestHookAddStacks(t *testing.T) {
func TestHooksNilEntry(t *testing.T) {
tests := []struct {
name string
hook hook
hook Hook
}{
{"AddStacks", AddStacks(InfoLevel).(hook)},
{"AddCaller", AddCaller().(hook)},
{"AddStacks", AddStacks(InfoLevel).(Hook)},
{"AddCaller", AddCaller().(Hook)},
}
for _, tt := range tests {
assert.NotPanics(t, func() {
Expand Down
2 changes: 1 addition & 1 deletion meta.go
Expand Up @@ -34,7 +34,7 @@ import (
type Meta struct {
Development bool
Encoder Encoder
Hooks []hook
Hooks []Hook
Output WriteSyncer
ErrorOutput WriteSyncer

Expand Down

0 comments on commit fd9cb2c

Please sign in to comment.