|
| 1 | +// You can modify this file to hook up a different logging library instead of logrus. |
| 2 | +// If you adapt to a different logging framework, you may need to use that |
| 3 | +// framework's equivalent of *Depth() functions so the file and line number printed |
| 4 | +// point to the real caller instead of your adapter function. |
| 5 | + |
| 6 | +package log |
| 7 | + |
| 8 | +import "github.com/sirupsen/logrus" |
| 9 | + |
| 10 | +// Level is used with V() to test log verbosity. |
| 11 | +type Level = logrus.Level |
| 12 | + |
| 13 | +var ( |
| 14 | + // V quickly checks if the logging verbosity meets a threshold. |
| 15 | + V = func(level int) bool { |
| 16 | + lvl := logrus.GetLevel() |
| 17 | + switch level { |
| 18 | + case 0: |
| 19 | + return lvl == logrus.InfoLevel |
| 20 | + case 1: |
| 21 | + return lvl == logrus.WarnLevel |
| 22 | + case 2: |
| 23 | + return lvl == logrus.ErrorLevel |
| 24 | + case 3: |
| 25 | + return lvl == logrus.FatalLevel |
| 26 | + default: |
| 27 | + return false |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + // Flush ensures any pending I/O is written. |
| 32 | + Flush = func() {} |
| 33 | + |
| 34 | + // Info formats arguments like fmt.Print. |
| 35 | + Info = logrus.Info |
| 36 | + // Infof formats arguments like fmt.Printf. |
| 37 | + Infof = logrus.Infof |
| 38 | + // InfoDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. |
| 39 | + InfoDepth = func(_ int, args ...interface{}) { |
| 40 | + logrus.Info(args...) |
| 41 | + } |
| 42 | + |
| 43 | + // Warning formats arguments like fmt.Print. |
| 44 | + Warning = logrus.Warning |
| 45 | + // Warningf formats arguments like fmt.Printf. |
| 46 | + Warningf = logrus.Warningf |
| 47 | + // WarningDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. |
| 48 | + WarningDepth = func(depth int, args ...interface{}) { |
| 49 | + logrus.Warning(args...) |
| 50 | + } |
| 51 | + |
| 52 | + // Error formats arguments like fmt.Print. |
| 53 | + Error = logrus.Error |
| 54 | + // Errorf formats arguments like fmt.Printf. |
| 55 | + Errorf = logrus.Errorf |
| 56 | + // ErrorDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. |
| 57 | + ErrorDepth = func(_ int, args ...interface{}) { |
| 58 | + logrus.Error(args...) |
| 59 | + } |
| 60 | + |
| 61 | + // Exit formats arguments like fmt.Print. |
| 62 | + Exit = logrus.Panic |
| 63 | + // Exitf formats arguments like fmt.Printf. |
| 64 | + Exitf = logrus.Panicf |
| 65 | + // ExitDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. |
| 66 | + ExitDepth = func(_ int, args ...interface{}) { |
| 67 | + logrus.Panic(args...) |
| 68 | + } |
| 69 | + |
| 70 | + // Fatal formats arguments like fmt.Print. |
| 71 | + Fatal = logrus.Fatal |
| 72 | + // Fatalf formats arguments like fmt.Printf |
| 73 | + Fatalf = logrus.Fatalf |
| 74 | + // FatalDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. |
| 75 | + FatalDepth = func(_ int, args ...interface{}) { |
| 76 | + logrus.Fatal(args...) |
| 77 | + } |
| 78 | +) |
0 commit comments