/
logs.go
62 lines (50 loc) · 1.3 KB
/
logs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"time"
"github.com/appscode/go/log"
pbs "github.com/datacol-io/datacol/api/controller"
pb "github.com/datacol-io/datacol/api/models"
"golang.org/x/net/websocket"
)
func (s *Server) LogStream(req *pbs.LogStreamReq, stream pbs.ProviderService_LogStreamServer) error {
return fmt.Errorf("Logging over GRPC has been deprecated. Please use use websocket based Path")
}
func (s *Server) LogStreamWs(ws *websocket.Conn) error {
headers := ws.Request().Header
app := headers.Get("app")
if app == "" {
return fmt.Errorf("Missing require param: app")
}
var (
since time.Duration
follow bool
)
if raw := headers.Get("since"); raw != "" {
duration, err := time.ParseDuration(raw)
if err != nil {
return err
}
since = duration
}
if raw := headers.Get("follow"); raw != "" {
follow = raw == "true"
}
return s.Provider.LogStream(app, ws, pb.LogStreamOptions{
Since: since,
Follow: follow,
Proctype: headers.Get("process"),
TailLines: headers.Get("lines"),
})
}
type logStreamW struct {
stream pbs.ProviderService_LogStreamServer
}
func (rs logStreamW) Write(p []byte) (n int, err error) {
if err = rs.stream.Send(&pbs.StreamMsg{
Data: p,
}); err != nil {
log.Errorf("sending bytes to stream %s: %v", string(p), err)
}
return len(p), err
}