feat: add audit logs and system configs
This commit is contained in:
@@ -3,18 +3,38 @@ package services
|
||||
import (
|
||||
"context"
|
||||
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type audit struct{}
|
||||
|
||||
func (s *audit) Log(ctx context.Context, operatorID int64, action, targetID, detail string) {
|
||||
func (s *audit) Log(ctx context.Context, tenantID, operatorID int64, action, targetID, detail string) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"audit": true,
|
||||
"tenant": tenantID,
|
||||
"operator": operatorID,
|
||||
"action": action,
|
||||
"target": targetID,
|
||||
"detail": detail,
|
||||
}).Info("Audit Log")
|
||||
|
||||
entry := &models.AuditLog{
|
||||
TenantID: tenantID,
|
||||
OperatorID: operatorID,
|
||||
Action: action,
|
||||
TargetID: targetID,
|
||||
Detail: detail,
|
||||
}
|
||||
if err := models.AuditLogQuery.WithContext(ctx).Create(entry); err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"audit": true,
|
||||
"tenant": tenantID,
|
||||
"operator": operatorID,
|
||||
"action": action,
|
||||
"target": targetID,
|
||||
}).WithError(err).Warn("Audit log persist failed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user