log: allow external definition of log handling (#1561)

* poc

* linter: fix

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-07-19 10:10:27 +10:00
committed by GitHub
parent 90fee94c76
commit db59b8540e
3 changed files with 42 additions and 4 deletions

17
log/custom_log_hooks.go Normal file
View File

@@ -0,0 +1,17 @@
package log
// CustomLogHook is a function type for external log handling. It should return
// true if the library's internal logging system should be bypassed, or false
// if the library's internal logging system should be used.
type CustomLogHook func(header, subLoggerName string, a ...any) (bypassLibraryLogSystem bool)
var customLogHook CustomLogHook
// SetCustomLogHook sets a custom log hook function that allows the complete
// bypass of the library's internal logging system. This is useful for
// implementing custom log handling.
func SetCustomLogHook(h CustomLogHook) {
mu.Lock()
customLogHook = h
mu.Unlock()
}