...

Source file src/github.com/sirupsen/logrus/hooks/writer/writer.go

Documentation: github.com/sirupsen/logrus/hooks/writer

     1  package writer
     2  
     3  import (
     4  	"io"
     5  
     6  	log "github.com/sirupsen/logrus"
     7  )
     8  
     9  // Hook is a hook that writes logs of specified LogLevels to specified Writer
    10  type Hook struct {
    11  	Writer    io.Writer
    12  	LogLevels []log.Level
    13  }
    14  
    15  // Fire will be called when some logging function is called with current hook
    16  // It will format log entry to string and write it to appropriate writer
    17  func (hook *Hook) Fire(entry *log.Entry) error {
    18  	line, err := entry.Bytes()
    19  	if err != nil {
    20  		return err
    21  	}
    22  	_, err = hook.Writer.Write(line)
    23  	return err
    24  }
    25  
    26  // Levels define on which log levels this hook would trigger
    27  func (hook *Hook) Levels() []log.Level {
    28  	return hook.LogLevels
    29  }
    30  

View as plain text