Skip to content

Commit

Permalink
Clean current output file name (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlallaouret authored and buger committed Jun 16, 2016
1 parent d0e1858 commit 2c49556
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions output_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"sort"
"strconv"
"strings"
"time"
"sync"
"time"
)

var dateFileNameFuncs = map[string]func() string{
Expand Down Expand Up @@ -170,7 +170,7 @@ func (o *FileOutput) filename() string {
}

func (o *FileOutput) updateName() {
o.currentName = o.filename()
o.currentName = filepath.Clean(o.filename())
}

func (o *FileOutput) Write(data []byte) (n int, err error) {
Expand Down
11 changes: 11 additions & 0 deletions output_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ func TestFileOutput(t *testing.T) {
close(quit)
}

func TestFileOutputWithNameCleaning(t *testing.T) {
output := &FileOutput{pathTemplate: "./test_requests.gor", config: &FileOutputConfig{flushInterval: time.Minute, append: false}}
expectedFileName := "test_requests_0.gor"
output.updateName()

if expectedFileName != output.currentName {
t.Errorf("Expected path %s but got %s", expectedFileName, output.currentName)
}

}

func TestFileOutputPathTemplate(t *testing.T) {
output := &FileOutput{pathTemplate: "/tmp/log-%Y-%m-%d-%S", config: &FileOutputConfig{flushInterval: time.Minute, append: true}}
now := time.Now()
Expand Down

0 comments on commit 2c49556

Please sign in to comment.