|
| 1 | +package log |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + "os" |
| 6 | + |
| 7 | + "github.com/devstream-io/devstream/cmd" |
| 8 | + "github.com/sirupsen/logrus" |
| 9 | +) |
| 10 | + |
| 11 | +var ( |
| 12 | + debugLog = &CliLoggerFormatter{showType: "debug"} |
| 13 | + infoLog = &CliLoggerFormatter{showType: "info"} |
| 14 | + warnLog = &CliLoggerFormatter{showType: "warn"} |
| 15 | + errorLog = &CliLoggerFormatter{showType: "error"} |
| 16 | + fatalLog = &CliLoggerFormatter{showType: "fatal"} |
| 17 | + successLog = &CliLoggerFormatter{showType: "success"} |
| 18 | +) |
| 19 | + |
| 20 | +func RedirectOutput(writer io.Writer) { |
| 21 | + logrus.SetOutput(writer) |
| 22 | +} |
| 23 | + |
| 24 | +func RecoverOutput() { |
| 25 | + if cmd.OutputFormat != "" { |
| 26 | + return |
| 27 | + } |
| 28 | + logrus.SetOutput(os.Stdout) |
| 29 | +} |
| 30 | + |
| 31 | +// Debugf log info with color,symbol and format for a notice |
| 32 | +func Debugf(format string, args ...interface{}) { |
| 33 | + logrus.SetFormatter(debugLog) |
| 34 | + logrus.Debugf(format, args...) |
| 35 | +} |
| 36 | + |
| 37 | +// Debug log info with color and symbol, for a notice |
| 38 | +func Debug(args ...interface{}) { |
| 39 | + logrus.SetFormatter(debugLog) |
| 40 | + logrus.Debug(args...) |
| 41 | +} |
| 42 | + |
| 43 | +// Infof log info with color,symbol and format for a notice |
| 44 | +func Infof(format string, args ...interface{}) { |
| 45 | + logrus.SetFormatter(infoLog) |
| 46 | + logrus.Infof(format, args...) |
| 47 | +} |
| 48 | + |
| 49 | +// Info log info with color and symbol, for a notice |
| 50 | +func Info(args ...interface{}) { |
| 51 | + logrus.SetFormatter(infoLog) |
| 52 | + logrus.Info(args...) |
| 53 | +} |
| 54 | + |
| 55 | +// Warnf log warn with color,symbol and format for a warning event |
| 56 | +func Warnf(format string, args ...interface{}) { |
| 57 | + logrus.SetFormatter(warnLog) |
| 58 | + logrus.Warnf(format, args...) |
| 59 | +} |
| 60 | + |
| 61 | +// Warn log warn with color and symbol, for a warning event |
| 62 | +func Warn(args ...interface{}) { |
| 63 | + logrus.SetFormatter(warnLog) |
| 64 | + logrus.Warn(args...) |
| 65 | +} |
| 66 | + |
| 67 | +// Errorf log error with color,symbol and format for a warning event |
| 68 | +func Errorf(format string, args ...interface{}) { |
| 69 | + logrus.SetFormatter(errorLog) |
| 70 | + logrus.Errorf(format, args...) |
| 71 | +} |
| 72 | + |
| 73 | +// Error log error with color adn symbol for a warning event |
| 74 | +func Error(args ...interface{}) { |
| 75 | + logrus.SetFormatter(errorLog) |
| 76 | + logrus.Error(args...) |
| 77 | +} |
| 78 | + |
| 79 | +// Fatalf log fatal with color,symbol and format for a fatal event |
| 80 | +func Fatalf(format string, args ...interface{}) { |
| 81 | + logrus.SetFormatter(fatalLog) |
| 82 | + logrus.Fatalf(format, args...) |
| 83 | +} |
| 84 | + |
| 85 | +// Fatal log fatal with color and symbol for a fatal event |
| 86 | +func Fatal(args ...interface{}) { |
| 87 | + logrus.SetFormatter(fatalLog) |
| 88 | + logrus.Fatal(args...) |
| 89 | +} |
| 90 | + |
| 91 | +// Successf log success with color,symbol and format for a success operation |
| 92 | +func Successf(format string, args ...interface{}) { |
| 93 | + logrus.SetFormatter(successLog) |
| 94 | + logrus.Infof(format, args...) |
| 95 | +} |
| 96 | + |
| 97 | +// Success log success with color and symbol, for a success operation |
| 98 | +func Success(args ...interface{}) { |
| 99 | + logrus.SetFormatter(successLog) |
| 100 | + logrus.Info(args...) |
| 101 | +} |
0 commit comments