// flushBuffer is a method for flushing the lines:
flushBuffer is a method for flushing the lines.
// flushBuffer is a method for flushing the lines :
func (adapter *Adapter) flushBuffer(buffer []Line) {
	defer func(begin time.Time) {
		adapter.instrumenting.fireAddRequestCount(flushBufferActionLabel)
		adapter.instrumenting.fireAddRequestLatency(begin, flushBufferActionLabel)
	}(time.Now())
	var data bytes.Buffer
	body := struct {
		Lines []Line `json:"lines"`
	}{
		Lines: buffer,
	}
	if error := json.NewEncoder(&data).Encode(body); error != nil {
		go adapter.instrumenting.fireAddFlushBufferEncodeDataError()
		adapter.Logger.Println(
			fmt.Errorf(
				"JSON Encoding Error: %s",
				error.Error(),
			),
		)
		return
	}
	urlValues := url.Values{}
	urlValues.Add("hostname", "logdna_logspout")
	url := "https://" + adapter.Config.LogDNAURL + "?" + urlValues.Encode()
	req, _ := http.NewRequest(http.MethodPost, url, &data)
	req.Header.Set("user-agent", "logspout/"+adapter.version)
	req.Header.Set("Content-Type", "application/json; charset=UTF-8")
	req.SetBasicAuth(adapter.Config.LogDNAKey, "")
	resp, err := adapter.HTTPClient.Do(req)
	if err != nil {
		go adapter.instrumenting.fireAddFlushBufferLogDNACodeError()
		adapter.Logger.Println(
			fmt.Errorf(
				"HTTP Client Post Request Error: %s",
				err.Error(),
			),
		)
		return
	}
	if resp != nil {
		go adapter.instrumenting.fireAddLogDNAClientRequest(flushBufferActionLabel, fmt.Sprint(resp.StatusCode))
		if resp.StatusCode != http.StatusOK {
			adapter.Logger.Println(
				fmt.Errorf(
					"Received Status Code: %d While Sending Message",
					resp.StatusCode,
				),
			)
		}
		defer resp.Body.Close()
	} else {
		go adapter.instrumenting.fireAddFlushBufferLogDNACodeError()
		adapter.Logger.Println(
			fmt.Errorf(
				"HTTP Client Post Request Error: %s",
				"request response is nil",
			),
		)
	}
}
func ( adapter * Adapter ) flushBuffer ( buffer [ ] Line ) { defer func ( begin time . Time ) { adapter . instrumenting . fireAddRequestCount ( flushBufferActionLabel ) adapter . instrumenting . fireAddRequestLatency ( begin , flushBufferActionLabel ) } ( time . Now ( ) ) var data bytes . Buffer body := struct { Lines [ ] Line `json:"lines"` } { Lines : buffer , } if error := json . NewEncoder ( & data ) . Encode ( body ) ; error != nil { go adapter . instrumenting . fireAddFlushBufferEncodeDataError ( ) adapter . Logger . Println ( fmt . Errorf ( " " , error . Error ( ) , ) , ) return } urlValues := url . Values { } urlValues . Add ( " " , " " ) url := " " + adapter . Config . LogDNAURL + " " + urlValues . Encode ( ) req , _ := http . NewRequest ( http . MethodPost , url , & data ) req . Header . Set ( " " , " " + adapter . version ) req . Header . Set ( " " , " " ) req . SetBasicAuth ( adapter . Config . LogDNAKey , " " ) resp , err := adapter . HTTPClient . Do ( req ) if err != nil { go adapter . instrumenting . fireAddFlushBufferLogDNACodeError ( ) adapter . Logger . Println ( fmt . Errorf ( " " , err . Error ( ) , ) , ) return } if resp != nil { go adapter . instrumenting . fireAddLogDNAClientRequest ( flushBufferActionLabel , fmt . Sprint ( resp . StatusCode ) ) if resp . StatusCode != http . StatusOK { adapter . Logger . Println ( fmt . Errorf ( " " , resp . StatusCode , ) , ) } defer resp . Body . Close ( ) } else { go adapter . instrumenting . fireAddFlushBufferLogDNACodeError ( ) adapter . Logger . Println ( fmt . Errorf ( " " , " " , ) , ) } }
flushBuffer is a method for flushing the lines.
flushBuffer is a method for flushing the lines .