diff --git a/go.mod b/go.mod index ba0f98a0..6d07aa51 100644 --- a/go.mod +++ b/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 diff --git a/middleware/accesslog/accesslog.go b/middleware/accesslog/accesslog.go index 195669b3..2adb23d3 100644 --- a/middleware/accesslog/accesslog.go +++ b/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.