forked from minamijoyo/hcledit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (32 loc) · 699 Bytes
/
main.go
File metadata and controls
39 lines (32 loc) · 699 Bytes
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
package main
import (
"fmt"
"io"
"log"
"os"
"github.com/hashicorp/logutils"
"github.com/minamijoyo/hcledit/cmd"
)
func main() {
log.SetOutput(logOutput())
log.Printf("[INFO] CLI args: %#v", os.Args)
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func logOutput() io.Writer {
levels := []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}
minLevel := os.Getenv("HCLEDIT_LOG")
// default log writer is null device.
writer := io.Discard
if minLevel != "" {
writer = os.Stderr
}
filter := &logutils.LevelFilter{
Levels: levels,
MinLevel: logutils.LogLevel(minLevel),
Writer: writer,
}
return filter
}