func appLog(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	var err error
	var lines int
	if l := r.URL.Query().Get("lines"); l != "" {
		lines, err = strconv.Atoi(l)
		if err != nil {
			msg := `Parameter "lines" must be an integer.`
			return &errors.HTTP{Code: http.StatusBadRequest, Message: msg}
		}
	} else {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: `Parameter "lines" is mandatory.`}
	}
	w.Header().Set("Content-Type", "application/x-json-stream")
	source := r.URL.Query().Get("source")
	unit := r.URL.Query().Get("unit")
	follow := r.URL.Query().Get("follow")
	appName := r.URL.Query().Get(":app")
	filterLog := app.Applog{Source: source, Unit: unit}
	a, err := getAppFromContext(appName, r)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermAppReadLog,
		contextsForApp(&a)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	logs, err := a.LastLogs(lines, filterLog)
	if err != nil {
		return err
	}
	encoder := json.NewEncoder(w)
	err = encoder.Encode(logs)
	if err != nil {
		return err
	}
	if follow != "1" {
		return nil
	}
	closeChan := r.Context().Done()
	l, err := app.NewLogListener(&a, filterLog)
	if err != nil {
		return err
	}
	logTracker.add(l)
	defer func() {
		logTracker.remove(l)
		l.Close()
	}()
	logChan := l.ListenChan()
	for {
		var logMsg app.Applog
		var chOpen bool
		select {
		case <-closeChan:
			return nil
		case logMsg, chOpen = <-logChan:
		}
		if !chOpen {
			return nil
		}
		err := encoder.Encode([]app.Applog{logMsg})
		if err != nil {
			break
		}
	}
	return nil
}
func appLog(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	var err error
	var lines int
	if l := r.URL.Query().Get("lines"); l != "" {
		lines, err = strconv.Atoi(l)
		if err != nil {
			msg := `Parameter "lines" must be an integer.`
			return &errors.HTTP{Code: http.StatusBadRequest, Message: msg}
		}
	} else {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: `Parameter "lines" is mandatory.`}
	}
	w.Header().Set("Content-Type", "application/x-json-stream")
	source := r.URL.Query().Get("source")
	unit := r.URL.Query().Get("unit")
	follow := r.URL.Query().Get("follow")
	appName := r.URL.Query().Get(":app")
	filterLog := app.Applog{Source: source, Unit: unit}
	a, err := getAppFromContext(appName, r)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermAppReadLog,
		contextsForApp(&a)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	logs, err := a.LastLogs(lines, filterLog)
	if err != nil {
		return err
	}
	encoder := json.NewEncoder(w)
	err = encoder.Encode(logs)
	if err != nil {
		return err
	}
	if follow != "1" {
		return nil
	}
	closeChan := r.Context().Done()
	l, err := app.NewLogListener(&a, filterLog)
	if err != nil {
		return err
	}
	logTracker.add(l)
	defer func() {
		logTracker.remove(l)
		l.Close()
	}()
	logChan := l.ListenChan()
	for {
		var logMsg app.Applog
		var chOpen bool
		select {
		case <-closeChan:
			return nil
		case logMsg, chOpen = <-logChan:
		}
		if !chOpen {
			return nil
		}
		err := encoder.Encode([]app.Applog{logMsg})
		if err != nil {
			break
		}
	}
	return nil
}
func appLog ( w http . ResponseWriter , r * http . Request , t auth . Token ) error { var err error var lines int if l := r . URL . Query ( ) . Get ( " " ) ; l != " " { lines , err = strconv . Atoi ( l ) if err != nil { msg := `Parameter "lines" must be an integer.` return & errors . HTTP { Code : http . StatusBadRequest , Message : msg } } } else { return & errors . HTTP { Code : http . StatusBadRequest , Message : `Parameter "lines" is mandatory.` } } w . Header ( ) . Set ( " " , " " ) source := r . URL . Query ( ) . Get ( " " ) unit := r . URL . Query ( ) . Get ( " " ) follow := r . URL . Query ( ) . Get ( " " ) appName := r . URL . Query ( ) . Get ( " " ) filterLog := app . Applog { Source : source , Unit : unit } a , err := getAppFromContext ( appName , r ) if err != nil { return err } allowed := permission . Check ( t , permission . PermAppReadLog , contextsForApp ( & a ) ... , ) if ! allowed { return permission . ErrUnauthorized } logs , err := a . LastLogs ( lines , filterLog ) if err != nil { return err } encoder := json . NewEncoder ( w ) err = encoder . Encode ( logs ) if err != nil { return err } if follow != " " { return nil } closeChan := r . Context ( ) . Done ( ) l , err := app . NewLogListener ( & a , filterLog ) if err != nil { return err } logTracker . add ( l ) defer func ( ) { logTracker . remove ( l ) l . Close ( ) } ( ) logChan := l . ListenChan ( ) for { var logMsg app . Applog var chOpen bool select { case <- closeChan : return nil case logMsg , chOpen = <- logChan : } if ! chOpen { return nil } err := encoder . Encode ( [ ] app . Applog { logMsg } ) if err != nil { break } } return nil }
// title: app log
// path: /apps/{app}/log
// method: GET
// produce: application/x-json-stream
// responses:
//   200: Ok
//   400: Invalid data
//   401: Unauthorized
//   404: App not found
title : app log path : / apps / { app } / log method : GET produce : application / x - json - stream responses : 200 : Ok 400 : Invalid data 401 : Unauthorized 404 : App not found