当前位置: 首页>>代码示例>>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;未经允许,请勿转载。