本文整理汇总了Golang中github.com/Sirupsen/logrus.Logger.Printf方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Printf方法的具体用法?Golang Logger.Printf怎么用?Golang Logger.Printf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Sirupsen/logrus.Logger
的用法示例。
在下文中一共展示了Logger.Printf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: catchPluginPanic
func catchPluginPanic(l *log.Logger) {
if err := recover(); err != nil {
trace := make([]byte, 4096)
count := runtime.Stack(trace, true)
l.Printf("Recover from panic: %s\n", err)
l.Printf("Stack of %d bytes: %s\n", count, trace)
panic(err)
}
}
示例2: publishDataToRmq
func publishDataToRmq(metrics []plugin.PluginMetricType, address string, exName string, rtKey string, exKind string, logger *log.Logger) error {
conn, err := amqp.Dial("amqp://" + address)
if err != nil {
logger.Printf("RMQ Publisher: cannot open connection, %s", err)
return err
}
defer conn.Close()
c, err := conn.Channel()
if err != nil {
logger.Printf("RMQ Publisher: cannot open channel: %s", err)
return err
}
err = c.ExchangeDeclare(exName, exKind, true, false, false, false, nil)
if err != nil {
logger.Printf("RMQ Publisher: cannot declare exchange: %v", err)
return err
}
data, err := json.Marshal(metrics)
if err != nil {
logger.Printf("RMQ Publisher: cannot marshal metrics: %v", err)
return err
}
msg := amqp.Publishing{
DeliveryMode: amqp.Persistent,
Timestamp: time.Now(),
ContentType: "text/plain",
Body: data,
}
err = c.Publish(exName, rtKey, false, false, msg)
if err != nil {
logger.Printf("RMQ Publisher: cannot publish metric %v", err)
return err
}
return nil
}