本文整理汇总了Golang中github.com/Sirupsen/logrus.Entry.Reader方法的典型用法代码示例。如果您正苦于以下问题:Golang Entry.Reader方法的具体用法?Golang Entry.Reader怎么用?Golang Entry.Reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Sirupsen/logrus.Entry
的用法示例。
在下文中一共展示了Entry.Reader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Fire
// Fire is called when an event should be sent to the message broker
func (n natsConn) Fire(entry *logrus.Entry) error {
ch := n.Conn
body, err := entry.Reader()
if err != nil {
return err
}
err = ch.Publish(n.params.Subject, body.Bytes())
if err != nil {
return err
}
return nil
}
示例2: logLogrusEntry
func (p *pusher) logLogrusEntry(entry *logrus.Entry) error {
if err := entry.Logger.Hooks.Fire(entry.Level, entry); err != nil {
return err
}
reader, err := entry.Reader()
if err != nil {
return err
}
p.lock.Lock()
defer p.lock.Unlock()
_, err = io.Copy(entry.Logger.Out, reader)
return err
}
示例3: Fire
// Fire - to implement logrus.Hook interface
func (kC kafkaConn) Fire(entry *logrus.Entry) error {
body, err := entry.Reader()
if err != nil {
return err
}
// Construct message to send to Kafka
msg := sarama.ProducerMessage{
Topic: kC.topic,
Value: sarama.ByteEncoder(body.Bytes()),
}
// Attempt sending the message to Kafka
_, _, err = kC.producer.SendMessage(&msg)
if err != nil {
return fmt.Errorf("Error sending event to Kafka - %v", err)
}
return nil
}
示例4: Fire
func (s SocketHook) Fire(entry *logrus.Entry) error {
c, err := net.Dial("unix", s.socketPath)
if err != nil {
// Airbrake someday
fmt.Println("Unable to dial socket:", err)
return nil
}
defer c.Close()
logMessageBuffer, err := entry.Reader()
if err != nil {
// Airbrake someday
return nil
}
_, err = c.Write(logMessageBuffer.Bytes())
if err != nil {
// Airbrake someday
fmt.Println("Unable to write to socket:", err)
}
return nil
}