mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 20:41:57 +00:00
:)
This commit is contained in:
@@ -337,7 +337,7 @@ func FileUnbuffered(path string) *AccessLog {
|
||||
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)
|
||||
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -1027,7 +1027,7 @@ func (ac *AccessLog) Print(ctx *context.Context,
|
||||
// but let's don't coplicate things so much
|
||||
// as the end-developer can use a custom template.
|
||||
func (ac *AccessLog) writeText(buf *bytes.Buffer, s string) {
|
||||
if len(s) == 0 {
|
||||
if s == "" {
|
||||
if len(ac.Blank) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -104,34 +104,29 @@ func TestAccessLogBroker(t *testing.T) {
|
||||
go func() {
|
||||
i := 0
|
||||
ln := broker.NewListener()
|
||||
for {
|
||||
select {
|
||||
case log, ok := <-ln:
|
||||
if !ok {
|
||||
if i != n {
|
||||
for i < n {
|
||||
wg.Done()
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
t.Log("Log Listener Closed: interrupted")
|
||||
return
|
||||
}
|
||||
for log := range ln {
|
||||
lat := log.Latency
|
||||
t.Log(lat.String())
|
||||
wg.Done()
|
||||
if expected := time.Duration(i) * time.Second; expected != lat {
|
||||
panic(fmt.Sprintf("expected latency: %s but got: %s", expected, lat))
|
||||
}
|
||||
time.Sleep(1350 * time.Millisecond)
|
||||
if log.Latency != lat {
|
||||
panic("expected logger to wait for notifier before release the log")
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
lat := log.Latency
|
||||
t.Log(lat.String())
|
||||
if i != n {
|
||||
for i < n {
|
||||
wg.Done()
|
||||
if expected := time.Duration(i) * time.Second; expected != lat {
|
||||
panic(fmt.Sprintf("expected latency: %s but got: %s", expected, lat))
|
||||
}
|
||||
time.Sleep(1350 * time.Millisecond)
|
||||
if log.Latency != lat {
|
||||
panic("expected logger to wait for notifier before release the log")
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
t.Log("Log Listener Closed: interrupted")
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
@@ -258,18 +253,15 @@ func TestAccessLogSetOutput(t *testing.T) {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
switch i {
|
||||
case 5:
|
||||
if w == nil {
|
||||
break
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
ac.SetOutput(w)
|
||||
if withSlowClose {
|
||||
end := time.Since(now)
|
||||
if end < time.Second {
|
||||
panic(fmt.Sprintf("[%s] [%d]: SetOutput should wait for previous Close. Expected to return a bit after %s but %s", name, i, time.Second, end))
|
||||
if i == 5 {
|
||||
if w != nil {
|
||||
now := time.Now()
|
||||
ac.SetOutput(w)
|
||||
if withSlowClose {
|
||||
end := time.Since(now)
|
||||
if end < time.Second {
|
||||
panic(fmt.Sprintf("[%s] [%d]: SetOutput should wait for previous Close. Expected to return a bit after %s but %s", name, i, time.Second, end))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// CSV is a Formatter type for csv encoded logs.
|
||||
type CSV struct { // TODO: change it to use csvutil.
|
||||
writer *csv.Writer
|
||||
|
||||
type CSV struct {
|
||||
writerPool *sync.Pool
|
||||
ac *AccessLog
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestCSV(t *testing.T) {
|
||||
|
||||
lat, _ := time.ParseDuration("1s")
|
||||
|
||||
print := func() {
|
||||
printFunc := func() {
|
||||
ac.Print(
|
||||
nil,
|
||||
lat,
|
||||
@@ -39,8 +39,8 @@ func TestCSV(t *testing.T) {
|
||||
}
|
||||
|
||||
// print twice, the header should only be written once.
|
||||
print()
|
||||
print()
|
||||
printFunc()
|
||||
printFunc()
|
||||
|
||||
expected := `Timestamp,Latency,Code,Method,Path,IP,Req Values,In,Out
|
||||
725864400000,1s,200,GET,/,::1,sleep=1s,573,81
|
||||
|
||||
Reference in New Issue
Block a user