...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package config
15
16 import (
17 "fmt"
18 "os"
19 "path/filepath"
20
21 "github.com/mitchellh/go-homedir"
22 "github.com/sirupsen/logrus"
23 )
24
25 func SetupLogger() {
26 logrusConfig()
27 }
28
29 func logrusConfig() {
30 logdir, err := homedir.Expand(GetCacheDir() + "/log")
31 if err != nil {
32 fmt.Fprintf(os.Stderr, "log: failed to find directory: %v", err)
33 logdir = os.TempDir()
34 }
35
36 logdir = filepath.Clean(logdir)
37 err = os.MkdirAll(logdir, os.ModeDir|0700)
38 if err != nil {
39 fmt.Fprintf(os.Stderr, "log: failed to create directory: %v", err)
40 logdir = os.TempDir()
41 }
42 file, err := os.OpenFile(filepath.Join(logdir, "ecr-login.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
43 if err != nil {
44 return
45 }
46 logrus.SetLevel(logrus.DebugLevel)
47 logrus.SetOutput(file)
48 }
49
View as plain text