Пример #1
0
func scanLogs(stream io.Reader) error {
	dispatcher := app.NewlogDispatcher(2000000, runtime.NumCPU())
	decoder := json.NewDecoder(stream)
	for {
		var entry app.Applog
		err := decoder.Decode(&entry)
		if err != nil {
			if err == io.EOF {
				break
			}
			dispatcher.Stop()
			return fmt.Errorf("wslogs: parsing log line: %s", err)
		}
		err = dispatcher.Send(&entry)
		if err != nil {
			// Do not disconnect by returning here, dispatcher will already
			// retry db connection and we gain nothing by ending the WS
			// connection.
			log.Errorf("wslogs: error storing log: %s", err)
		}
	}
	err := dispatcher.Stop()
	if err != nil {
		return fmt.Errorf("wslogs: error storing log: %s", err)
	}
	return nil
}
Пример #2
0
func addLogs(ws *websocket.Conn) {
	var err error
	defer func() {
		data := map[string]interface{}{}
		if err != nil {
			data["error"] = err.Error()
			log.Error(err.Error())
		} else {
			data["error"] = nil
		}
		msg, _ := json.Marshal(data)
		ws.Write(msg)
		ws.Close()
	}()
	req := ws.Request()
	t := context.GetAuthToken(req)
	if t == nil {
		err = fmt.Errorf("wslogs: no token")
		return
	}
	if t.GetAppName() != app.InternalAppName {
		err = fmt.Errorf("wslogs: invalid token app name: %q", t.GetAppName())
		return
	}
	dispatcher := app.NewlogDispatcher()
	scanner := bufio.NewScanner(ws)
	for scanner.Scan() {
		var entry app.Applog
		data := bytes.TrimSpace(scanner.Bytes())
		if len(data) == 0 {
			continue
		}
		err = json.Unmarshal(data, &entry)
		if err != nil {
			dispatcher.Stop()
			err = fmt.Errorf("wslogs: parsing log line %q: %s", string(data), err)
			return
		}
		err = dispatcher.Send(&entry)
		if err != nil {
			// Do not disconnect by returning here, dispatcher will already
			// retry db connection and we gain nothing by ending the WS
			// connection.
			log.Errorf("wslogs: error storing log: %s", err)
		}
	}
	err = dispatcher.Stop()
	if err != nil {
		err = fmt.Errorf("wslogs: error storing log: %s", err)
		return
	}
	err = scanner.Err()
	if err != nil {
		err = fmt.Errorf("wslogs: waiting for log data: %s", err)
		return
	}
}
Пример #3
0
func scanLogs(stream io.Reader) error {
	dispatcher := app.NewlogDispatcher(2000000, runtime.NumCPU())
	decoder := json.NewDecoder(stream)
	for {
		var entry app.Applog
		err := decoder.Decode(&entry)
		if err != nil {
			if err == io.EOF {
				break
			}
			dispatcher.Stop()
			return fmt.Errorf("wslogs: parsing log line: %s", err)
		}
		dispatcher.Send(&entry)
	}
	dispatcher.Stop()
	return nil
}
Пример #4
0
Файл: log.go Проект: tsuru/tsuru
func scanLogs(stream io.Reader) error {
	queueSize, _ := config.GetInt("server:app-log-buffer-size")
	if queueSize == 0 {
		queueSize = 500000
	}
	dispatcher := app.NewlogDispatcher(queueSize, runtime.NumCPU())
	decoder := json.NewDecoder(stream)
	for {
		var entry app.Applog
		err := decoder.Decode(&entry)
		if err != nil {
			if err == io.EOF {
				break
			}
			dispatcher.Stop()
			return errors.Wrap(err, "wslogs: parsing log line")
		}
		dispatcher.Send(&entry)
	}
	dispatcher.Stop()
	return nil
}