Browse Source

hooks: expose LevelHooks type

tags/v0.8.3
Simon Eskildsen 4 years ago
parent
commit
93a1736895
2 changed files with 6 additions and 6 deletions
  1. 3
    3
      hooks.go
  2. 3
    3
      logger.go

+ 3
- 3
hooks.go View File

@@ -11,11 +11,11 @@ type Hook interface {
11 11
 }
12 12
 
13 13
 // Internal type for storing the hooks on a logger instance.
14
-type levelHooks map[Level][]Hook
14
+type LevelHooks map[Level][]Hook
15 15
 
16 16
 // Add a hook to an instance of logger. This is called with
17 17
 // `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface.
18
-func (hooks levelHooks) Add(hook Hook) {
18
+func (hooks LevelHooks) Add(hook Hook) {
19 19
 	for _, level := range hook.Levels() {
20 20
 		hooks[level] = append(hooks[level], hook)
21 21
 	}
@@ -23,7 +23,7 @@ func (hooks levelHooks) Add(hook Hook) {
23 23
 
24 24
 // Fire all the hooks for the passed level. Used by `entry.log` to fire
25 25
 // appropriate hooks for a log entry.
26
-func (hooks levelHooks) Fire(level Level, entry *Entry) error {
26
+func (hooks LevelHooks) Fire(level Level, entry *Entry) error {
27 27
 	for _, hook := range hooks[level] {
28 28
 		if err := hook.Fire(entry); err != nil {
29 29
 			return err

+ 3
- 3
logger.go View File

@@ -14,7 +14,7 @@ type Logger struct {
14 14
 	// Hooks for the logger instance. These allow firing events based on logging
15 15
 	// levels and log entries. For example, to send errors to an error tracking
16 16
 	// service, log to StatsD or dump the core on fatal errors.
17
-	Hooks levelHooks
17
+	Hooks LevelHooks
18 18
 	// All log entries pass through the formatter before logged to Out. The
19 19
 	// included formatters are `TextFormatter` and `JSONFormatter` for which
20 20
 	// TextFormatter is the default. In development (when a TTY is attached) it
@@ -37,7 +37,7 @@ type Logger struct {
37 37
 //    var log = &Logger{
38 38
 //      Out: os.Stderr,
39 39
 //      Formatter: new(JSONFormatter),
40
-//      Hooks: make(levelHooks),
40
+//      Hooks: make(LevelHooks),
41 41
 //      Level: logrus.DebugLevel,
42 42
 //    }
43 43
 //
@@ -46,7 +46,7 @@ func New() *Logger {
46 46
 	return &Logger{
47 47
 		Out:       os.Stderr,
48 48
 		Formatter: new(TextFormatter),
49
-		Hooks:     make(levelHooks),
49
+		Hooks:     make(LevelHooks),
50 50
 		Level:     InfoLevel,
51 51
 	}
52 52
 }

Loading…
Cancel
Save