forked from evandigby/rtblogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 1021 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
43
44
45
46
47
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/evandigby/rtb"
"github.com/evandigby/rtb/amqp"
"os"
)
func main() {
var fileName string
var ampqAddress string
flag.StringVar(&qAddress, "amqp-address", "amqp://guest:guest@localhost:5672/", "AMQP Logging address.")
flag.StringVar(&fileName, "filename", "", "File to write to (stdout if not specified)")
flag.Parse()
if fileName == "" {
fmt.Println("No file name specified, logging to screen.")
}
var logConsumer rtb.BidLogConsumer
logConsumer = amqp.NewAmqpBidLogger(ampqAddress, "rtb-interview")
logChan := logConsumer.LogChannel()
for logItem := range logChan {
js, err := json.Marshal(logItem)
if err != nil {
return
}
if fileName == "" {
fmt.Println(string(js[:]))
} else {
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
fmt.Println("Error writing to log file.")
} else {
fmt.Fprintln(file, string(js[:]), "\n")
file.Close()
}
}
}
}