photoprism/internal/event/audit.go
Michael Mayer f5a8c5a45d Auth: Session and ACL enhancements #98 #1746
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 09:01:17 +02:00

40 lines
910 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package event
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
)
// AuditLog optionally logs security events.
var AuditLog Logger
var AuditPrefix = "audit: "
// Format formats an audit log event.
func Format(ev []string, args ...interface{}) string {
return fmt.Sprintf(strings.Join(ev, " "), args...)
}
// Audit optionally reports security-relevant events.
func Audit(level logrus.Level, ev []string, args ...interface{}) {
if AuditLog != nil && len(ev) > 0 {
AuditLog.Log(level, AuditPrefix+Format(ev, args...))
}
}
func AuditErr(ev []string, args ...interface{}) {
Audit(logrus.ErrorLevel, ev, args...)
}
func AuditWarn(ev []string, args ...interface{}) {
Audit(logrus.WarnLevel, ev, args...)
}
func AuditInfo(ev []string, args ...interface{}) {
Audit(logrus.InfoLevel, ev, args...)
}
func AuditDebug(ev []string, args ...interface{}) {
Audit(logrus.DebugLevel, ev, args...)
}