本文整理汇总了Golang中github.com/Sirupsen/logrus.Logger.Warnln方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Warnln方法的具体用法?Golang Logger.Warnln怎么用?Golang Logger.Warnln使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Sirupsen/logrus.Logger
的用法示例。
在下文中一共展示了Logger.Warnln方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: calculateMovingAverage
func (p *movingAverageProcessor) calculateMovingAverage(m plugin.MetricType, logger *log.Logger) (float64, error) {
namespace := concatNameSpace(m.Namespace().Strings())
switch v := m.Data().(type) {
default:
logger.Warnln(fmt.Sprintf("Unknown data received: Type %T", v))
return 0.0, nil
case int:
if _, ok := p.movingAverageMap[namespace]; ok {
counter, err := p.getCounter(namespace)
counterCurrent := counter % p.movingBufLength
err = p.addBufferData(counterCurrent, m.Data(), namespace)
if err != nil {
return 0.0, err
}
sum := int(0)
//Initial Counter is used to give correct average for initial iterations ie when the buffer is not full
initialCounter := 0
for i := 0; i < p.movingBufLength; i++ {
if p.getBufferData(i, namespace) != nil {
initialCounter++
sum += p.getBufferData(i, namespace).(int)
}
}
movingAvg := float64(sum) / float64(initialCounter)
counterCurrent++
p.setCounter(namespace, counterCurrent)
return movingAvg, err
} else {
//Since map doesnot have an entry of this namespace, it's creating an entry for the namespace.
//Also m.data value is inserted into 0th position of the buffer because we know that this buffer is being used for the first time
p.movingAverageMap[namespace] = newmovingAverage(p.getBufferLength())
err := p.addBufferData(0, m.Data(), namespace)
if err != nil {
return 0.0, err
}
sum := p.getBufferData(0, namespace).(int)
p.setCounter(namespace, 1)
return float64(sum), nil
}
case float64:
if _, ok := p.movingAverageMap[namespace]; ok {
counter, err := p.getCounter(namespace)
counterCurrent := counter % p.movingBufLength
err = p.addBufferData(counterCurrent, m.Data(), namespace)
if err != nil {
return 0.0, err
}
sum := float64(0)
initialCounter := 0
for i := 0; i < p.movingBufLength; i++ {
if p.getBufferData(i, namespace) != nil {
initialCounter++
sum += p.getBufferData(i, namespace).(float64)
}
}
movingAvg := float64(sum) / float64(initialCounter)
counterCurrent++
p.setCounter(namespace, counterCurrent)
return movingAvg, err
}
p.movingAverageMap[namespace] = newmovingAverage(p.getBufferLength())
err := p.addBufferData(0, m.Data(), namespace)
if err != nil {
return 0.0, err
}
sum := p.getBufferData(0, namespace).(float64)
p.setCounter(namespace, 1)
return float64(sum), nil
case float32:
if _, ok := p.movingAverageMap[namespace]; ok {
counter, err := p.getCounter(namespace)
counterCurrent := counter % p.movingBufLength
err = p.addBufferData(counterCurrent, m.Data(), namespace)
if err != nil {
return 0.0, err
}
sum := float32(0)
initialCounter := 0
for i := 0; i < p.movingBufLength; i++ {
if p.getBufferData(i, namespace) != nil {
initialCounter++
sum += p.getBufferData(i, namespace).(float32)
}
}
movingAvg := float64(sum) / float64(initialCounter)
p.setCounter(namespace, counterCurrent)
return movingAvg, err
//.........这里部分代码省略.........