Esempio n. 1
0
// Fire is called when a log event is fired.
func (hook *PapertrailHook) Fire(entry *logrus.Entry) error {
	date := time.Now().Format(format)
	msg, _ := entry.String()
	payload := fmt.Sprintf("<22> %s %s: %s", date, hook.AppName, msg)

	bytesWritten, err := hook.UDPConn.Write([]byte(payload))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to send log line to Papertrail via UDP. Wrote %d bytes before error: %v", bytesWritten, err)
		return err
	}

	return nil
}
Esempio n. 2
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
}
Esempio n. 3
0
func (hook *SyslogHook) Fire(entry *logrus.Entry) error {
	line, err := entry.String()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
		return err
	}

	switch entry.Level {
	case logrus.PanicLevel:
		return hook.Writer.Crit(line)
	case logrus.FatalLevel:
		return hook.Writer.Crit(line)
	case logrus.ErrorLevel:
		return hook.Writer.Err(line)
	case logrus.WarnLevel:
		return hook.Writer.Warning(line)
	case logrus.InfoLevel:
		return hook.Writer.Info(line)
	case logrus.DebugLevel:
		return hook.Writer.Debug(line)
	default:
		return nil
	}
}