-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (53 loc) · 1.03 KB
/
main.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
63
64
65
66
67
package main
import (
"bufio"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
)
var logs Logs
// GCPLogFormat ...
type GCPLogFormat struct {
Message string `json:"message"`
Severity string `json:"severity"`
Labels map[string]string `json:"logging.googleapis.com/labels"`
}
// Log ...
type Log struct {
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
GCPLogger GCPLogFormat `json:"google"`
}
type Logs []Log
func startHttp() {
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
err := http.ListenAndServe(":8080", r)
if err != nil {
log.Fatalln(err)
}
}
func main() {
gcp := GCPLogger{}
// Read from stdin
reader := bufio.NewReader(os.Stdin)
logs = make(Logs, 0)
go startHttp()
for {
text, _, _ := reader.ReadLine()
if text != nil {
// Init Log
l := Log{
Message: string(text),
Timestamp: time.Now(),
}
// Capture GCP Container
_ = gcp.Read(text, &l)
logs = append(logs, l)
fmt.Println(string(text))
}
}
}