mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
accesslog: add FileUnbuffered helper
This commit is contained in:
parent
3e6fd79906
commit
a2d0b86815
2
go.mod
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
|
||||
|
|
|
@ -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…
Reference in New Issue
Block a user