-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.go
41 lines (33 loc) · 798 Bytes
/
init.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
package main
import (
"fmt"
"os"
"runtime"
"strings"
"github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus"
)
var opts struct {
LogLevel string `long:"log_level" default:"info" description:"log level"`
McastAddr string `long:"mcast_addr" default:"239.0.0.0:9999" description:"multicast address"`
}
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func init() {
parser := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash|flags.IgnoreUnknown)
_, err := parser.Parse()
if err != nil {
fmt.Printf("%v", err)
os.Exit(-1)
}
}
func init() {
if level, err := log.ParseLevel(strings.ToLower(opts.LogLevel)); err != nil {
log.SetLevel(level)
}
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
}