From 7055d769582dc852d72c04fab044ca8deb9b3a89 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 29 Apr 2015 21:03:39 +0200 Subject: [PATCH] use forked lumberjack (buffers writes) --- Godeps/Godeps.json | 10 +++++----- .../lumberjack.v2/.gitignore | 0 .../lumberjack.v2/LICENSE | 0 .../lumberjack.v2/README.md | 0 .../lumberjack.v2/chown.go | 0 .../lumberjack.v2/chown_linux.go | 0 .../lumberjack.v2/example_test.go | 0 .../lumberjack.v2/linux_test.go | 0 .../lumberjack.v2/lumberjack.go | 11 ++++++++++- .../lumberjack.v2/lumberjack_test.go | 17 +++++++++++++++++ .../lumberjack.v2/rotate_test.go | 0 .../lumberjack.v2/testing_test.go | 0 thirdparty/eventlog/option.go | 2 +- 13 files changed, 33 insertions(+), 7 deletions(-) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/.gitignore (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/LICENSE (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/README.md (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/chown.go (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/chown_linux.go (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/example_test.go (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/linux_test.go (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/lumberjack.go (98%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/lumberjack_test.go (97%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/rotate_test.go (100%) rename Godeps/_workspace/src/gopkg.in/{natefinch => cryptix}/lumberjack.v2/testing_test.go (100%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index d5a512507..492e377cd 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -275,16 +275,16 @@ "ImportPath": "golang.org/x/net/context", "Rev": "7dbad50ab5b31073856416cdcfeb2796d682f844" }, + { + "ImportPath": "gopkg.in/cryptix/lumberjack.v2", + "Comment": "v1.0-13-gb9ca6a4", + "Rev": "b9ca6a494a971c67b412b38c88ccdbc096d1c9af" + }, { "ImportPath": "gopkg.in/fsnotify.v1", "Comment": "v1.2.0", "Rev": "96c060f6a6b7e0d6f75fddd10efeaca3e5d1bcb0" }, - { - "ImportPath": "gopkg.in/natefinch/lumberjack.v2", - "Comment": "v1.0-12-gd28785c", - "Rev": "d28785c2f27cd682d872df46ccd8232843629f54" - }, { "ImportPath": "gopkg.in/tomb.v1", "Rev": "dd632973f1e7218eb1089048e0798ec9ae7dceb8" diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/.gitignore b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/.gitignore similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/.gitignore rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/.gitignore diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/LICENSE b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/LICENSE similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/LICENSE rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/LICENSE diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/README.md b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/README.md similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/README.md rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/README.md diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/chown.go similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/chown.go diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown_linux.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/chown_linux.go similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown_linux.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/chown_linux.go diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/example_test.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/example_test.go similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/example_test.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/example_test.go diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/linux_test.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/linux_test.go similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/linux_test.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/linux_test.go diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack.go similarity index 98% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack.go index 2e5d28302..af30d2c16 100644 --- a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack.go +++ b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack.go @@ -22,6 +22,7 @@ package lumberjack import ( + "bufio" "fmt" "io" "io/ioutil" @@ -94,6 +95,7 @@ type Logger struct { size int64 file *os.File + bw *bufio.Writer mu sync.Mutex } @@ -137,7 +139,7 @@ func (l *Logger) Write(p []byte) (n int, err error) { } } - n, err = l.file.Write(p) + n, err = l.bw.Write(p) l.size += int64(n) return n, err @@ -155,6 +157,11 @@ func (l *Logger) close() error { if l.file == nil { return nil } + + if err := l.bw.Flush(); err != nil { + return err + } + err := l.file.Close() l.file = nil return err @@ -219,6 +226,7 @@ func (l *Logger) openNew() error { return fmt.Errorf("can't open new logfile: %s", err) } l.file = f + l.bw = bufio.NewWriter(l.file) l.size = 0 return nil } @@ -258,6 +266,7 @@ func (l *Logger) openExistingOrNew(writeLen int) error { file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644) if err == nil { l.file = file + l.bw = bufio.NewWriter(l.file) l.size = info.Size() return nil } diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack_test.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack_test.go similarity index 97% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack_test.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack_test.go index e9984f807..74e2fa3a1 100644 --- a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack_test.go +++ b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack_test.go @@ -41,6 +41,7 @@ func TestNewFile(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(logFile(dir), n, t) fileCount(dir, 1, t) } @@ -65,6 +66,7 @@ func TestOpenExisting(t *testing.T) { isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) // make sure the file got appended existsWithLen(filename, len(data)+n, t) @@ -106,6 +108,7 @@ func TestMakeLogDir(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(logFile(dir), n, t) fileCount(dir, 1, t) } @@ -122,6 +125,7 @@ func TestDefaultFilename(t *testing.T) { isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(filename, n, t) } @@ -142,6 +146,7 @@ func TestAutoRotate(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(filename, n, t) fileCount(dir, 1, t) @@ -152,6 +157,7 @@ func TestAutoRotate(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b2), n, t) + isNil(l.bw.Flush(), t) // the old logfile should be moved aside and the main logfile should have // only the last write in it. @@ -187,6 +193,7 @@ func TestFirstWriteRotate(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(filename, n, t) existsWithLen(backupFile(dir), len(start), t) @@ -211,6 +218,7 @@ func TestMaxBackups(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(filename, n, t) fileCount(dir, 1, t) @@ -222,6 +230,7 @@ func TestMaxBackups(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b2), n, t) + isNil(l.bw.Flush(), t) // this will use the new fake time secondFilename := backupFile(dir) @@ -238,6 +247,7 @@ func TestMaxBackups(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b2), n, t) + isNil(l.bw.Flush(), t) // this will use the new fake time thirdFilename := backupFile(dir) @@ -280,6 +290,7 @@ func TestMaxBackups(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b2), n, t) + isNil(l.bw.Flush(), t) // this will use the new fake time fourthFilename := backupFile(dir) @@ -326,6 +337,7 @@ func TestMaxAge(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(filename, n, t) fileCount(dir, 1, t) @@ -337,6 +349,7 @@ func TestMaxAge(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b2), n, t) + isNil(l.bw.Flush(), t) existsWithLen(backupFile(dir), len(b), t) // we need to wait a little bit since the files get deleted on a different @@ -359,6 +372,7 @@ func TestMaxAge(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b3), n, t) + isNil(l.bw.Flush(), t) existsWithLen(backupFile(dir), len(b2), t) // we need to wait a little bit since the files get deleted on a different @@ -454,6 +468,7 @@ func TestLocalTime(t *testing.T) { n2, err := l.Write(b2) isNil(err, t) equals(len(b2), n2, t) + isNil(l.bw.Flush(), t) existsWithLen(logFile(dir), n2, t) existsWithLen(backupFileLocal(dir), n, t) @@ -476,6 +491,7 @@ func TestRotate(t *testing.T) { n, err := l.Write(b) isNil(err, t) equals(len(b), n, t) + isNil(l.bw.Flush(), t) existsWithLen(filename, n, t) fileCount(dir, 1, t) @@ -511,6 +527,7 @@ func TestRotate(t *testing.T) { n, err = l.Write(b2) isNil(err, t) equals(len(b2), n, t) + isNil(l.Close(), t) // this will use the new fake time existsWithLen(filename, n, t) diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/rotate_test.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/rotate_test.go similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/rotate_test.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/rotate_test.go diff --git a/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/testing_test.go b/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/testing_test.go similarity index 100% rename from Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/testing_test.go rename to Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/testing_test.go diff --git a/thirdparty/eventlog/option.go b/thirdparty/eventlog/option.go index a04ab7b3c..e5680e018 100644 --- a/thirdparty/eventlog/option.go +++ b/thirdparty/eventlog/option.go @@ -5,7 +5,7 @@ import ( "os" "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2" + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2" ) // init sets up sane defaults