示例#1
0
// 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
0
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
0
// 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
0
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
}