当前位置: 首页>>代码示例>>Golang>>正文


Golang Logger.Warnln方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:intelsdi-x,项目名称:snap-plugin-processor-movingaverage,代码行数:101,代码来源:movingaverage.go


注:本文中的github.com/Sirupsen/logrus.Logger.Warnln方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。