blob: 925ac19dfebb523e2356883ba61caf359559dad9 [file] [log] [blame]
package auditlog
import (
type auditLog struct {
Type string `json:"type"`
Action string `json:"action"`
User string `json:"user"`
Body interface{} `json:"body"`
// LogWithUser is used to create structured logs for auditable actions.
// This is only intended to be used on GKE, since by default GKE is
// configured to handle structured logs emitted on stdout and stderr.
// See:
// user should be an identifier for the user from the login system.
func LogWithUser(r *http.Request, user, action string, body interface{}) {
a := auditLog{
Type: "audit",
Action: action,
User: user,
Body: body,
b, err := json.Marshal(a)
if err != nil {
sklog.Errorf("Failed to marshall audit log entry: %s", err)