Browse Source

accesslog: add FileUnbuffered helper

pull/1701/head
Gerasimos (Makis) Maropoulos 1 year ago
parent
commit
a2d0b86815
No known key found for this signature in database GPG Key ID: 5DBE766BD26A54E7
  1. 2
      go.mod
  2. 14
      middleware/accesslog/accesslog.go

2
go.mod

@ -21,7 +21,7 @@ require (
github.com/json-iterator/go v1.1.10
github.com/kataras/blocks v0.0.4
github.com/kataras/golog v0.1.6
github.com/kataras/jwt v0.0.8
github.com/kataras/jwt v0.0.9
github.com/kataras/neffos v0.0.18
github.com/kataras/pio v0.0.10
github.com/kataras/sitemap v0.0.5

14
middleware/accesslog/accesslog.go

@ -323,6 +323,18 @@ func New(w io.Writer) *AccessLog {
//
// It panics on error.
func File(path string) *AccessLog {
f := mustOpenFile(path)
return New(bufio.NewReadWriter(bufio.NewReader(f), bufio.NewWriter(f)))
}
// FileUnbuffered same as File but it does not buffers the data,
// it flushes the loggers contents as soon as possible.
func FileUnbuffered(path string) *AccessLog {
f := mustOpenFile(path)
return New(f)
}
func mustOpenFile(path string) *os.File {
// Note: we add os.RDWR in order to be able to read from it,
// some formatters (e.g. CSV) needs that.
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
@ -330,7 +342,7 @@ func File(path string) *AccessLog {
panic(err)
}
return New(bufio.NewReadWriter(bufio.NewReader(f), bufio.NewWriter(f)))
return f
}
// Broker creates or returns the broker.

Loading…
Cancel
Save