-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (33 loc) · 831 Bytes
/
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
package main
import (
"flag"
"journald-forwarder/journald"
"journald-forwarder/loggly"
"log"
"os"
"runtime"
"time"
)
var token = flag.String("token", "", "Loggly Token")
var logFile = flag.String("logfile", "/var/log/journald-forwarder.log", "Path to log file to write")
var tag = flag.String("tag", "", "tag to use on Loggly")
func main() {
flag.Parse()
if *token == "" {
log.Fatalf("-token is required.")
}
runtime.GOMAXPROCS(runtime.NumCPU())
f, err := os.OpenFile(*logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
c := make(chan journald.JournalEntry, 2)
uri := loggly.GenerateUri(*token, *tag)
go journald.CollectJournal(c)
go loggly.ProcessJournal(c, uri)
for {
time.Sleep(1 * time.Second)
}
}