Updates per jsha's review
This commit is contained in:
parent
a77152e828
commit
cead23df00
|
|
@ -58,7 +58,7 @@ func NewAuditLogger(log *syslog.Writer, stats statsd.Statter) (*AuditLogger, err
|
||||||
|
|
||||||
// initializeAuditLogger should only be used in unit tests. Failures in this
|
// initializeAuditLogger should only be used in unit tests. Failures in this
|
||||||
// method are unlikely as the defaults are safe, and they are also
|
// method are unlikely as the defaults are safe, and they are also
|
||||||
// of minimal consequence during unit testing -- logs get pritned to stdout
|
// of minimal consequence during unit testing -- logs get printed to stdout
|
||||||
// even if syslog is missing.
|
// even if syslog is missing.
|
||||||
func initializeAuditLogger() {
|
func initializeAuditLogger() {
|
||||||
stats, _ := statsd.NewNoopClient(nil)
|
stats, _ := statsd.NewNoopClient(nil)
|
||||||
|
|
@ -71,10 +71,14 @@ func initializeAuditLogger() {
|
||||||
// SetAuditLogger configures the singleton audit logger. This method
|
// SetAuditLogger configures the singleton audit logger. This method
|
||||||
// must only be called once, and before calling GetAuditLogger the
|
// must only be called once, and before calling GetAuditLogger the
|
||||||
// first time.
|
// first time.
|
||||||
func SetAuditLogger(logger *AuditLogger) {
|
func SetAuditLogger(logger *AuditLogger) (err error) {
|
||||||
_Singleton.once.Do(func() {
|
if _Singleton.log != nil {
|
||||||
|
err = errors.New("You may not call SetAuditLogger after it has already been implicitly or explicitly set.")
|
||||||
|
_Singleton.log.WarningErr(err)
|
||||||
|
} else {
|
||||||
_Singleton.log = logger
|
_Singleton.log = logger
|
||||||
})
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuditLogger obtains the singleton audit logger. If SetAuditLogger
|
// GetAuditLogger obtains the singleton audit logger. If SetAuditLogger
|
||||||
|
|
@ -82,7 +86,11 @@ func SetAuditLogger(logger *AuditLogger) {
|
||||||
// The basic defaults cannot error, and subequent access to an already-set
|
// The basic defaults cannot error, and subequent access to an already-set
|
||||||
// AuditLogger also cannot error, so this method is error-safe.
|
// AuditLogger also cannot error, so this method is error-safe.
|
||||||
func GetAuditLogger() *AuditLogger {
|
func GetAuditLogger() *AuditLogger {
|
||||||
|
_Singleton.once.Do(func() {
|
||||||
|
if _Singleton.log == nil {
|
||||||
initializeAuditLogger()
|
initializeAuditLogger()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return _Singleton.log
|
return _Singleton.log
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,10 @@ func TestSingleton(t *testing.T) {
|
||||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||||
|
|
||||||
// Should not work
|
// Should not work
|
||||||
SetAuditLogger(log3)
|
err = SetAuditLogger(log3)
|
||||||
|
test.AssertError(t, err, "Can't re-set")
|
||||||
|
|
||||||
|
// Verify no change
|
||||||
log4 := GetAuditLogger()
|
log4 := GetAuditLogger()
|
||||||
|
|
||||||
// Verify that log4 != log3
|
// Verify that log4 != log3
|
||||||
|
|
@ -117,7 +120,3 @@ func TestSyslogMethods(t *testing.T) {
|
||||||
audit.Warning("audit-logger_test.go: warning")
|
audit.Warning("audit-logger_test.go: warning")
|
||||||
audit.Alert("audit-logger_test.go: alert")
|
audit.Alert("audit-logger_test.go: alert")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmergSyslog(t *testing.T) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue