|
31 | 31 | // limitations under the License. |
32 | 32 | package log |
33 | 33 |
|
| 34 | +import ( |
| 35 | + "fmt" |
| 36 | + "runtime" |
| 37 | +) |
| 38 | + |
34 | 39 | var ( |
35 | 40 | internalLog *logMux |
| 41 | + debugMode bool |
36 | 42 | ) |
37 | 43 |
|
38 | 44 | /* |
@@ -61,24 +67,57 @@ so that we have a very simple API to get started with. |
61 | 67 | */ |
62 | 68 |
|
63 | 69 | func Info(message string, v ...interface{}) { |
64 | | - internalLog.Info(message, v...) |
| 70 | + // Prepend the log message with information about the calling function. |
| 71 | + var fileMessage string |
| 72 | + if debugMode { |
| 73 | + _, f, l, _ := runtime.Caller(1) |
| 74 | + fileMessage = fmt.Sprintf("(%s:%d) %s", f, l, message) |
| 75 | + } else { |
| 76 | + fileMessage = message |
| 77 | + } |
| 78 | + internalLog.Info(fileMessage, v...) |
65 | 79 | } |
66 | 80 |
|
67 | 81 | func Warning(message string, v ...interface{}) { |
68 | | - internalLog.Warning(message, v...) |
| 82 | + // Prepend the log message with information about the calling function. |
| 83 | + var fileMessage string |
| 84 | + if debugMode { |
| 85 | + _, f, l, _ := runtime.Caller(1) |
| 86 | + fileMessage = fmt.Sprintf("(%s:%d) %s", f, l, message) |
| 87 | + } else { |
| 88 | + fileMessage = message |
| 89 | + } |
| 90 | + internalLog.Warning(fileMessage, v...) |
69 | 91 | } |
70 | 92 |
|
71 | 93 | func Error(message string, v ...interface{}) { |
72 | | - internalLog.Error(message, v...) |
| 94 | + // Prepend the log message with information about the calling function. |
| 95 | + var fileMessage string |
| 96 | + if debugMode { |
| 97 | + _, f, l, _ := runtime.Caller(1) |
| 98 | + fileMessage = fmt.Sprintf("(%s:%d) %s", f, l, message) |
| 99 | + } else { |
| 100 | + fileMessage = message |
| 101 | + } |
| 102 | + internalLog.Error(fileMessage, v...) |
73 | 103 | } |
74 | 104 |
|
75 | 105 | func Debug(message string, v ...interface{}) { |
76 | | - internalLog.Debug(message, v...) |
| 106 | + // Prepend the log message with information about the calling function. |
| 107 | + var fileMessage string |
| 108 | + if debugMode { |
| 109 | + _, f, l, _ := runtime.Caller(1) |
| 110 | + fileMessage = fmt.Sprintf("(%s:%d) %s", f, l, message) |
| 111 | + } else { |
| 112 | + fileMessage = message |
| 113 | + } |
| 114 | + internalLog.Debug(fileMessage, v...) |
77 | 115 | } |
78 | 116 |
|
79 | 117 | /* |
80 | 118 | DebugMode sets the debug mode option for this built-in logger. |
81 | 119 | */ |
82 | 120 | func DebugMode(status bool) { |
83 | 121 | internalLog.DebugMode(status) |
| 122 | + debugMode = status |
84 | 123 | } |
0 commit comments