本文整理匯總了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
//.........這裏部分代碼省略.........