forked from rakutentech/cf-metrics-refinery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (39 loc) · 1.08 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
package main
import (
"flag"
"log"
"os"
"strings"
"github.com/hashicorp/logutils"
"github.com/rakutentech/cf-metrics-refinery/cli"
)
func main() {
flags := flag.NewFlagSet((&cli.CLI{}).Name(), flag.ExitOnError) // FIXME: ugly
logLevel := flags.String("log-level", "INFO", "")
flags.SetOutput(os.Stderr)
flags.Usage = func() {
err := cli.ConfigUsage(os.Stderr)
if err != nil {
log.Fatal("[ERROR] Failed to provide Config usage: ", err)
}
}
flags.Parse(os.Args[1:])
cliConfig, err := cli.ConfigParse()
if err != nil {
log.Fatal("[ERROR] Failed to parse env configurations: ", err)
}
app := &cli.CLI{
OutStream: os.Stdout,
ErrStream: os.Stderr,
Conf: cliConfig,
}
// Setup logger with level Filtering
logger := log.New(&logutils.LevelFilter{
Levels: []logutils.LogLevel{"DEBUG", "INFO", "ERROR"},
MinLevel: (logutils.LogLevel)(strings.ToUpper(*logLevel)),
Writer: app.OutStream,
}, "", log.LstdFlags)
logger.Printf("[INFO] %s version %s", app.Name(), app.Version())
logger.Printf("[DEBUG] LogLevel: %s", *logLevel)
os.Exit(app.Run(logger))
}