本文整理汇总了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
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例6: Fire
func (gc *GuiClient) Fire(entry *log.Entry) error {
line, err := entry.String()
if err != nil {
return err
}
gc.Warnf(line)
return nil
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}
示例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
}
}
示例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
}