Add LogSanitizer interface, and ability to call it from ForceLog
This commit is contained in:
Родитель
55fedc85a6
Коммит
5c9876f0cd
|
@ -253,3 +253,22 @@ type methodFactoryMarker struct {
|
|||
func (methodFactoryMarker) New(next Policy, po *PolicyOptions) Policy {
|
||||
panic("methodFactoryMarker policy should have been replaced with a method policy")
|
||||
}
|
||||
|
||||
// LogSanitizer can be implemented to clean secrets from lines logged by ForceLog
|
||||
// By default no implemetation is provided here, because pipeline may be used in many different
|
||||
// contexts, so the correct implementation is context-dependent
|
||||
type LogSanitizer interface {
|
||||
SanitizeLogLine(raw string) string
|
||||
}
|
||||
|
||||
var sanitizer LogSanitizer
|
||||
|
||||
// SetLogSanitizer can be called to supply a custom LogSanitizer.
|
||||
// There is no threadsafety or locking on the underlying variable,
|
||||
// so call this function just once at startup of your application
|
||||
// (Don't later try to change the sanitizer on the fly).
|
||||
func SetLogSanitizer(s LogSanitizer)(){
|
||||
sanitizer = s
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package pipeline
|
||||
|
||||
|
||||
// ForceLog should rarely be used. It forceable logs an entry to the
|
||||
// Windows Event Log (on Windows) or to the SysLog (on Linux)
|
||||
func ForceLog(level LogLevel, msg string) {
|
||||
if sanitizer != nil {
|
||||
msg = sanitizer.SanitizeLogLine(msg)
|
||||
}
|
||||
forceLog(level, msg)
|
||||
}
|
|
@ -7,9 +7,9 @@ import (
|
|||
"log/syslog"
|
||||
)
|
||||
|
||||
// ForceLog should rarely be used. It forceable logs an entry to the
|
||||
// forceLog should rarely be used. It forceable logs an entry to the
|
||||
// Windows Event Log (on Windows) or to the SysLog (on Linux)
|
||||
func ForceLog(level LogLevel, msg string) {
|
||||
func forceLog(level LogLevel, msg string) {
|
||||
if defaultLogger == nil {
|
||||
return // Return fast if we failed to create the logger.
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
// ForceLog should rarely be used. It forceable logs an entry to the
|
||||
// forceLog should rarely be used. It forceable logs an entry to the
|
||||
// Windows Event Log (on Windows) or to the SysLog (on Linux)
|
||||
func ForceLog(level LogLevel, msg string) {
|
||||
func forceLog(level LogLevel, msg string) {
|
||||
var el eventType
|
||||
switch level {
|
||||
case LogError, LogFatal, LogPanic:
|
||||
|
|
Загрузка…
Ссылка в новой задаче