mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
Logs: Refactor message formatting in event package
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
a2186f3fa4
commit
dce754182e
3 changed files with 14 additions and 10 deletions
|
|
@ -1,21 +1,12 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// AuditLog optionally logs security events.
|
||||
var AuditLog Logger
|
||||
var AuditPrefix = "audit: "
|
||||
var AuditMessageSep = " › "
|
||||
|
||||
// Format formats an audit log event.
|
||||
func Format(ev []string, args ...interface{}) string {
|
||||
return fmt.Sprintf(strings.Join(ev, AuditMessageSep), args...)
|
||||
}
|
||||
|
||||
// Audit optionally reports security-relevant events.
|
||||
func Audit(level logrus.Level, ev []string, args ...interface{}) {
|
||||
|
|
@ -35,7 +26,7 @@ func Audit(level logrus.Level, ev []string, args ...interface{}) {
|
|||
// Publish event if log level is info or higher.
|
||||
if level <= logrus.InfoLevel {
|
||||
Publish(
|
||||
"audit."+level.String(),
|
||||
"audit.log."+level.String(),
|
||||
Data{
|
||||
"time": TimeStamp(),
|
||||
"level": level.String(),
|
||||
|
|
|
|||
13
internal/event/format.go
Normal file
13
internal/event/format.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var MessageSep = " › "
|
||||
|
||||
// Format formats an audit log event.
|
||||
func Format(ev []string, args ...interface{}) string {
|
||||
return fmt.Sprintf(strings.Join(ev, MessageSep), args...)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue