|
14 | 14 |
|
15 | 15 | package log |
16 | 16 |
|
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "strings" |
| 20 | +) |
| 21 | + |
17 | 22 | type Log interface { |
18 | 23 | Trace(msg string) |
19 | 24 | Tracef(format string, args ...interface{}) |
@@ -100,34 +105,33 @@ func Criticalf(format string, args ...interface{}) { |
100 | 105 | pluginLog.Criticalf(format, args...) |
101 | 106 | } |
102 | 107 |
|
103 | | -// UnsafeInfo logs a message at Info level only if safe log mode is disabled. |
104 | | -// Use this for sensitive information that should not be logged in production. |
| 108 | +// UnsafeInfo logs a message at Info level when safe log mode is disabled. |
| 109 | +// When safe log mode is enabled, the message is downgraded to Debug level |
| 110 | +// with newlines preserved (not escaped), so that line-based log collectors |
| 111 | +// cannot capture the complete sensitive information. |
105 | 112 | func UnsafeInfo(msg string) { |
106 | | - if !safeLogEnabled { |
| 113 | + if safeLogEnabled { |
| 114 | + // In safe mode, downgrade to Debug level and preserve newlines |
| 115 | + // to prevent log collectors from capturing complete sensitive data |
| 116 | + msg = strings.ReplaceAll(msg, `\n`, "\n") |
| 117 | + pluginLog.Debug(msg) |
| 118 | + } else { |
107 | 119 | pluginLog.Info(msg) |
108 | 120 | } |
109 | 121 | } |
110 | 122 |
|
111 | | -// UnsafeInfof logs a formatted message at Info level only if safe log mode is disabled. |
112 | | -// Use this for sensitive information that should not be logged in production. |
| 123 | +// UnsafeInfof logs a formatted message at Info level when safe log mode is disabled. |
| 124 | +// When safe log mode is enabled, the message is downgraded to Debug level |
| 125 | +// with newlines preserved (not escaped), so that line-based log collectors |
| 126 | +// cannot capture the complete sensitive information. |
113 | 127 | func UnsafeInfof(format string, args ...interface{}) { |
114 | | - if !safeLogEnabled { |
115 | | - pluginLog.Infof(format, args...) |
116 | | - } |
117 | | -} |
118 | | - |
119 | | -// UnsafeDebug logs a message at Debug level only if safe log mode is disabled. |
120 | | -// Use this for sensitive information that should not be logged in production. |
121 | | -func UnsafeDebug(msg string) { |
122 | | - if !safeLogEnabled { |
| 128 | + if safeLogEnabled { |
| 129 | + // In safe mode, downgrade to Debug level and preserve newlines |
| 130 | + // to prevent log collectors from capturing complete sensitive data |
| 131 | + msg := fmt.Sprintf(format, args...) |
| 132 | + msg = strings.ReplaceAll(msg, `\n`, "\n") |
123 | 133 | pluginLog.Debug(msg) |
124 | | - } |
125 | | -} |
126 | | - |
127 | | -// UnsafeDebugf logs a formatted message at Debug level only if safe log mode is disabled. |
128 | | -// Use this for sensitive information that should not be logged in production. |
129 | | -func UnsafeDebugf(format string, args ...interface{}) { |
130 | | - if !safeLogEnabled { |
131 | | - pluginLog.Debugf(format, args...) |
| 134 | + } else { |
| 135 | + pluginLog.Infof(format, args...) |
132 | 136 | } |
133 | 137 | } |
0 commit comments