-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
49 lines (40 loc) · 911 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
48
49
package main
import (
"fmt"
"os"
"strings"
_ "github.com/joho/godotenv/autoload"
fluentd "github.com/joonix/log"
log "github.com/sirupsen/logrus"
"github.com/jderusse/http-broadcast/pkg/broadcaster"
)
func initLogger() {
format := os.Getenv("LOG_FORMAT")
switch strings.ToLower(format) {
case "json":
log.SetFormatter(&log.JSONFormatter{})
case "":
case "text":
log.SetFormatter(&log.TextFormatter{})
case "fluentd":
log.SetFormatter(fluentd.NewFormatter())
default:
log.Error(fmt.Sprintf(`Unexpected log format "%s"`, format))
}
if level := os.Getenv("LOG_LEVEL"); level != "" {
l, err := log.ParseLevel(level)
if err != nil {
log.Error(fmt.Sprintf(`Unexpected log level "%s"`, level))
} else {
log.SetLevel(l)
}
}
}
func main() {
initLogger()
broadcaster, err := broadcaster.NewBroadcasterFromEnv()
if err != nil {
log.Fatalln(err)
}
broadcaster.Run()
}