當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。