當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Entry.String方法代碼示例

本文整理匯總了Golang中github.com/Sirupsen/logrus.Entry.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang Entry.String方法的具體用法?Golang Entry.String怎麽用?Golang Entry.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/Sirupsen/logrus.Entry的用法示例。


在下文中一共展示了Entry.String方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: send

func (s *fileSender) send(entry *logrus.Entry) (err error) {
	msg, err := entry.String()
	if err != nil {
		return
	}

	file, err := os.OpenFile(utils.GetLogPath(),
		os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		err = &WriteError{
			errors.Wrap(err, "logger: Failed to open log file"),
		}
		return
	}
	defer file.Close()

	_, err = file.WriteString(msg)
	if err != nil {
		err = &WriteError{
			errors.Wrap(err, "logger: Failed to write to log file"),
		}
		return
	}

	return
}
開發者ID:pathcode,項目名稱:pritunl-client-electron,代碼行數:26,代碼來源:file.go

示例2: Fire

// Open the file, write to the file, close the file.
// Whichever user is running the function needs write permissions to the file or directory if the file does not yet exist.
func (hook *lfsHook) Fire(entry *logrus.Entry) error {
	var (
		fd   *os.File
		path string
		msg  string
		err  error
		ok   bool
	)
	if path, ok = hook.paths[entry.Level]; !ok {
		err = fmt.Errorf("no file provided for loglevel: %d", entry.Level)
		log.Println(err.Error())
		return err
	}
	fd, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		log.Println("failed to open logfile:", path, err)
		return err
	}
	defer fd.Close()
	msg, err = entry.String()
	if err != nil {
		log.Println("failed to generate string for entry:", err)
		return err
	}
	fd.WriteString(msg)
	return nil
}
開發者ID:ahjdzx,項目名稱:dis,代碼行數:29,代碼來源:lfshook.go

示例3: Fire

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)
	case logrus.TraceLevel:
		return hook.Writer.Debug(line)
	default:
		return nil
	}
}
開發者ID:chendrak,項目名稱:logrus,代碼行數:26,代碼來源:syslog.go

示例4: Fire

func (h *StreamHook) Fire(entry *logrus.Entry) error {
	h.Lock()
	defer h.Unlock()

	var line string
	var err error

	if line, err = entry.String(); err != nil {
		if h.debug {
			fmt.Fprintf(os.Stderr, "Unable to read entry: %v\n", err)
		}
		return err
	}
	if h.terminator != "" {
		line += h.terminator
	}
	if _, err := h.writer.WriteString(line); err != nil {
		if h.debug {
			fmt.Fprintf(os.Stderr, "Unable to write the content: %v\n", err)
		}
		return err
	}
	if err := h.writer.Flush(); err != nil {
		if h.debug {
			fmt.Fprintf(os.Stderr, "Unable to flush the buffer: %v\n", err)
		}
		return err
	}

	return nil
}
開發者ID:xgfone,項目名稱:go-rotating,代碼行數:31,代碼來源:stream.go

示例5: Fire

// Fire fires the file logger hook and logs to the file.
func (l *localFile) Fire(entry *logrus.Entry) error {
	line, err := entry.String()
	if err != nil {
		return fmt.Errorf("Unable to read entry, %v", err)
	}
	l.File.Write([]byte(line + "\n"))
	l.File.Sync()
	return nil
}
開發者ID:hackintoshrao,項目名稱:minio,代碼行數:10,代碼來源:logger-file-hook.go

示例6: Fire

func (gc *GuiClient) Fire(entry *log.Entry) error {
	line, err := entry.String()
	if err != nil {
		return err
	}

	gc.Warnf(line)
	return nil
}
開發者ID:davidlazar,項目名稱:vuvuzela,代碼行數:9,代碼來源:gui.go

示例7: Fire

// Fire action to take when log is fired.
func (hook *LogErrorHook) Fire(entry *logrus.Entry) error {
	_, err := entry.String()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
		return err
	}

	go hook.reportErrors(entry)
	return nil
}
開發者ID:sagar8192,項目名稱:fullerite,代碼行數:11,代碼來源:collector_hook.go

示例8: Fire

//Fire is called when a log event is fired.
func (hook *TCPLoggingHook) Fire(entry *logrus.Entry) error {
	msg, _ := entry.String()

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

	return nil
}
開發者ID:xtracdev,項目名稱:xavi,代碼行數:12,代碼來源:logginghook.go

示例9: Fire

// Fire is called when an event should be sent to the message broker.k
func (q amqpConn) Fire(entry *logrus.Entry) error {
	ch, err := q.Connection.Channel()
	if err != nil {
		// Any other error other than connection closed, return.
		if err != amqp.ErrClosed {
			return err
		}
		// Attempt to connect again.
		var conn *amqp.Connection
		conn, err = amqp.Dial(q.params.URL)
		if err != nil {
			return err
		}
		ch, err = conn.Channel()
		if err != nil {
			return err
		}
	}
	defer ch.Close()

	err = ch.ExchangeDeclare(
		q.params.Exchange,
		q.params.ExchangeType,
		q.params.Durable,
		q.params.AutoDeleted,
		q.params.Internal,
		q.params.NoWait,
		nil,
	)
	if err != nil {
		return err
	}

	body, err := entry.String()
	if err != nil {
		return err
	}

	err = ch.Publish(
		q.params.Exchange,
		q.params.RoutingKey,
		q.params.Mandatory,
		q.params.Immediate,
		amqp.Publishing{
			ContentType: "application/json",
			Body:        []byte(body),
		})
	if err != nil {
		return err
	}

	return nil
}
開發者ID:hackintoshrao,項目名稱:minio,代碼行數:54,代碼來源:notify-amqp.go

示例10: Fire

// 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
}
開發者ID:CadeLaRen,項目名稱:dockercraft,代碼行數:14,代碼來源:papertrail.go

示例11: Fire

// Fire is called when an event should be sent to the message broker.
func (r redisConn) Fire(entry *logrus.Entry) error {
	rConn := r.Pool.Get()
	defer rConn.Close()

	data, err := entry.String()
	if err != nil {
		return err
	}

	_, err = rConn.Do("RPUSH", r.params.Key, data)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:hackintoshrao,項目名稱:minio,代碼行數:16,代碼來源:notify-redis.go

示例12: Fire

// Fire - fire the log event
func (hook *syslogHook) Fire(entry *logrus.Entry) error {
	line, err := entry.String()
	if err != nil {
		return fmt.Errorf("Unable to read entry, %v", 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)
	default:
		return nil
	}
}
開發者ID:hackintoshrao,項目名稱:minio,代碼行數:17,代碼來源:logger-syslog-hook_nix.go

示例13: Fire

// Fire is called when an event should be sent to the message broker
func (hook *AMQPHook) Fire(entry *logrus.Entry) error {
	dialURL := fmt.Sprintf("amqp://%s:%[email protected]%s/", hook.Username, hook.Password, hook.AMQPServer)
	conn, err := amqp.Dial(dialURL)
	if err != nil {
		return err
	}
	defer conn.Close()

	ch, err := conn.Channel()
	if err != nil {
		return nil
	}
	defer ch.Close()

	err = ch.ExchangeDeclare(
		hook.Exchange,
		hook.ExchangeType,
		hook.Durable,
		hook.AutoDeleted,
		hook.Internal,
		hook.NoWait,
		nil,
	)
	if err != nil {
		return err
	}

	body, err := entry.String()
	if err != nil {
		return err
	}

	err = ch.Publish(
		hook.Exchange,
		hook.RoutingKey,
		hook.Mandatory,
		hook.Immediate,
		amqp.Publishing{
			ContentType: "text/plain",
			Body:        []byte(body),
		})
	if err != nil {
		return err
	}

	return nil
}
開發者ID:vladoatanasov,項目名稱:logrus_amqp,代碼行數:48,代碼來源:logrus_amqp.go

示例14: Fire

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.Data["level"] {
	case "panic":
		return hook.Writer.Crit(line)
	case "fatal":
		return hook.Writer.Crit(line)
	case "error":
		return hook.Writer.Err(line)
	case "warn":
		return hook.Writer.Warning(line)
	case "info":
		return hook.Writer.Info(line)
	case "debug":
		return hook.Writer.Debug(line)
	default:
		return nil
	}
}
開發者ID:Blystad,項目名稱:deis,代碼行數:24,代碼來源:syslog.go

示例15: Fire

func (s *ServiceLogHook) Fire(entry *logrus.Entry) error {
	if entry.Level > s.Level {
		return nil
	}

	switch entry.Level {
	case logrus.PanicLevel, logrus.FatalLevel, logrus.ErrorLevel:
		s.Error(entry.String())
	case logrus.WarnLevel:
		s.Warning(entry.String())
	case logrus.InfoLevel:
		s.Info(entry.String())
	}
	return nil
}
開發者ID:bssthu,項目名稱:gitlab-ci-multi-runner,代碼行數:15,代碼來源:service.go


注:本文中的github.com/Sirupsen/logrus.Entry.String方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。