| 92 | } |
| 93 | |
| 94 | func setupDebugMode() { |
| 95 | // Show the file, line number and function name when logging |
| 96 | log.SetReportCaller(true) |
| 97 | |
| 98 | // Tweak the output since the defaults are not good |
| 99 | customTextFormatter := &log.TextFormatter{ |
| 100 | CallerPrettyfier: func(f *runtime.Frame) (string, string) { |
| 101 | // The full path is way too long. Extract just the file name. |
| 102 | shortFile := filepath.Base(f.File) |
| 103 | |
| 104 | // The function name includes the full package which is also way too long. |
| 105 | // Extract just the function name by itself. |
| 106 | // (We're abusing filepath.Ext here but I think we can get away with it) |
| 107 | shortFunction := filepath.Ext(f.Function)[1:] |
| 108 | |
| 109 | // Include the line number as well |
| 110 | shortFileandLineNumber := fmt.Sprintf(" %s:%d", shortFile, f.Line) |
| 111 | |
| 112 | return shortFunction, shortFileandLineNumber |
| 113 | }, |
| 114 | } |
| 115 | log.SetFormatter(customTextFormatter) |
| 116 | } |
| 117 | |
| 118 | // logrusSink implements logr.LogSink to pass klog messages to logrus |
| 119 | type logrusSink struct { |