refactor: init audit logger when first used (#2369)

This commit is contained in:
Benjamin Eder 2023-03-12 20:33:48 +01:00
parent 17996a06c4
commit 47879d1bcc
No known key found for this signature in database
GPG Key ID: 21B6BE3EC42C7B29
3 changed files with 12 additions and 10 deletions

View File

@ -4,10 +4,9 @@ import "log"
var auditLogger *log.Logger var auditLogger *log.Logger
func init() { func getAuditLogger() *log.Logger {
setupAuditLogger() if auditLogger == nil {
}
func setupAuditLogger() {
auditLogger = log.Default() auditLogger = log.Default()
} }
return auditLogger
}

View File

@ -8,9 +8,12 @@ import (
func TestSetupAuditLogger(t *testing.T) { func TestSetupAuditLogger(t *testing.T) {
auditLogger = nil auditLogger = nil
setupAuditLogger() result := getAuditLogger()
if auditLogger != log.Default() { if result != log.Default() {
t.Error("Audit logger isn't set to the default logger!") t.Error("Audit logger wasn't initialized with the default logger!")
}
if auditLogger != result {
t.Error("Audit logger wasn't set globally!")
} }
} }

View File

@ -22,5 +22,5 @@ func createLogMessage(info ResourceActivity) string {
} }
func logToAuditLogger(message string) { func logToAuditLogger(message string) {
auditLogger.Println(message) getAuditLogger().Println(message)
} }