diff --git a/builtin/audit/file/backend.go b/builtin/audit/file/backend.go index 0b05b0a3d3dc..4f39cc7bfb8f 100644 --- a/builtin/audit/file/backend.go +++ b/builtin/audit/file/backend.go @@ -159,6 +159,18 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr return err } + if err := b.formatter.FormatRequest(b.f, b.formatConfig, auth, req, outerErr); err == nil { + return nil + } + + // Opportunistically try to re-open the FD, once per call + b.f.Close() + b.f = nil + + if err := b.open(); err != nil { + return err + } + return b.formatter.FormatRequest(b.f, b.formatConfig, auth, req, outerErr) } @@ -175,6 +187,18 @@ func (b *Backend) LogResponse( return err } + if err := b.formatter.FormatResponse(b.f, b.formatConfig, auth, req, resp, err); err == nil { + return nil + } + + // Opportunistically try to re-open the FD, once per call + b.f.Close() + b.f = nil + + if err := b.open(); err != nil { + return err + } + return b.formatter.FormatResponse(b.f, b.formatConfig, auth, req, resp, err) }