| skipped 9 lines |
10 | 10 | | // "github.com/Sirupsen/logrus" |
11 | 11 | | "github.com/fatih/color" |
12 | 12 | | "github.com/sirupsen/logrus" |
| 13 | + | prefixed "github.com/x-cray/logrus-prefixed-formatter" |
13 | 14 | | ) |
14 | 15 | | |
15 | | - | var log = logrus.New() |
| 16 | + | var logger = logrus.New() |
16 | 17 | | |
17 | 18 | | // InitLog init log |
18 | 19 | | func InitLog(options Options) { |
| skipped 7 lines |
26 | 27 | | logFile := path.Join(logDir, "metabigor.log") |
27 | 28 | | f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) |
28 | 29 | | if err != nil { |
29 | | - | log.Fatalf("error opening file: %v", err) |
| 30 | + | logger.Error("error opening file: %v", err) |
30 | 31 | | } |
31 | 32 | | |
32 | 33 | | // defer f.Close() |
33 | 34 | | mwr := io.MultiWriter(os.Stdout, f) |
34 | | - | log.SetOutput(mwr) |
| 35 | + | |
| 36 | + | logger.SetLevel(logrus.InfoLevel) |
| 37 | + | |
| 38 | + | logger = &logrus.Logger{ |
| 39 | + | Out: mwr, |
| 40 | + | Level: logrus.InfoLevel, |
| 41 | + | Formatter: &prefixed.TextFormatter{ |
| 42 | + | ForceColors: true, |
| 43 | + | ForceFormatting: true, |
| 44 | + | }, |
| 45 | + | } |
35 | 46 | | |
36 | 47 | | if options.Debug == true { |
37 | | - | log.SetOutput(mwr) |
38 | | - | log.SetLevel(logrus.DebugLevel) |
| 48 | + | logger.SetOutput(mwr) |
| 49 | + | logger.SetLevel(logrus.DebugLevel) |
39 | 50 | | } else if options.Verbose == true { |
40 | | - | log.SetOutput(mwr) |
41 | | - | log.SetLevel(logrus.InfoLevel) |
| 51 | + | logger.SetOutput(mwr) |
| 52 | + | logger.SetLevel(logrus.InfoLevel) |
42 | 53 | | } else { |
43 | | - | log.SetOutput(ioutil.Discard) |
| 54 | + | logger.SetOutput(ioutil.Discard) |
44 | 55 | | } |
45 | | - | log.Info(fmt.Sprintf("Store log file to: %v", logFile)) |
| 56 | + | logger.Info(fmt.Sprintf("Store log file to: %v", logFile)) |
46 | 57 | | } |
47 | 58 | | |
48 | 59 | | // GoodF print good message |
| skipped 5 lines |
54 | 65 | | // BannerF print info message |
55 | 66 | | func BannerF(format string, data string) { |
56 | 67 | | banner := color.BlueString("[*] %v", format) |
57 | | - | log.Info(fmt.Sprintf("%v%v", banner, color.HiGreenString(data))) |
| 68 | + | logger.Info(fmt.Sprintf("%v%v", banner, color.HiGreenString(data))) |
58 | 69 | | } |
59 | 70 | | |
60 | 71 | | // InforF print info message |
61 | 72 | | func InforF(format string, args ...interface{}) { |
62 | | - | log.Info(fmt.Sprintf(format, args...)) |
| 73 | + | logger.Info(fmt.Sprintf(format, args...)) |
63 | 74 | | } |
64 | 75 | | |
65 | 76 | | // WarningF print good message |
| skipped 4 lines |
70 | 81 | | |
71 | 82 | | // DebugF print debug message |
72 | 83 | | func DebugF(format string, args ...interface{}) { |
73 | | - | log.Debug(fmt.Sprintf(format, args...)) |
| 84 | + | logger.Debug(fmt.Sprintf(format, args...)) |
74 | 85 | | } |
75 | 86 | | |
76 | 87 | | // ErrorF print good message |
| skipped 5 lines |