use forked lumberjack (buffers writes)
Henry committed
Apr 29, 2015 at 21:03 UTC
7055d769582dc852d72c04fab044ca8deb9b3a89
13 files changed
+33
-7
Godeps/Godeps.json
+5
-5
@@ -275,16 +275,16 @@
275
"ImportPath": "golang.org/x/net/context",
276
"Rev": "7dbad50ab5b31073856416cdcfeb2796d682f844"
277
},
278
+ {
279
+ "ImportPath": "gopkg.in/cryptix/lumberjack.v2",
280
+ "Comment": "v1.0-13-gb9ca6a4",
281
+ "Rev": "b9ca6a494a971c67b412b38c88ccdbc096d1c9af"
282
+ },
283
{
284
"ImportPath": "gopkg.in/fsnotify.v1",
285
"Comment": "v1.2.0",
286
"Rev": "96c060f6a6b7e0d6f75fddd10efeaca3e5d1bcb0"
287
},
283
- {
284
- "ImportPath": "gopkg.in/natefinch/lumberjack.v2",
285
- "Comment": "v1.0-12-gd28785c",
286
- "Rev": "d28785c2f27cd682d872df46ccd8232843629f54"
287
- },
288
{
289
"ImportPath": "gopkg.in/tomb.v1",
290
"Rev": "dd632973f1e7218eb1089048e0798ec9ae7dceb8"
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/.gitignore
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/LICENSE
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/README.md
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/chown.go
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/chown_linux.go
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/example_test.go
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/linux_test.go
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack.go
renamed
+10
-1
@@ -22,6 +22,7 @@
22
package lumberjack
23
24
import (
25
+ "bufio"
26
"fmt"
27
"io"
28
"io/ioutil"
@@ -94,6 +95,7 @@ type Logger struct {
95
96
size int64
97
file *os.File
98
+ bw *bufio.Writer
99
mu sync.Mutex
100
}
101
@@ -137,7 +139,7 @@ func (l *Logger) Write(p []byte) (n int, err error) {
139
}
140
}
141
140
- n, err = l.file.Write(p)
142
+ n, err = l.bw.Write(p)
143
l.size += int64(n)
144
145
return n, err
@@ -155,6 +157,11 @@ func (l *Logger) close() error {
157
if l.file == nil {
158
return nil
159
}
160
+
161
+ if err := l.bw.Flush(); err != nil {
162
+ return err
163
+ }
164
+
165
err := l.file.Close()
166
l.file = nil
167
return err
@@ -219,6 +226,7 @@ func (l *Logger) openNew() error {
226
return fmt.Errorf("can't open new logfile: %s", err)
227
}
228
l.file = f
229
+ l.bw = bufio.NewWriter(l.file)
230
l.size = 0
231
return nil
232
}
@@ -258,6 +266,7 @@ func (l *Logger) openExistingOrNew(writeLen int) error {
266
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
267
if err == nil {
268
l.file = file
269
+ l.bw = bufio.NewWriter(l.file)
270
l.size = info.Size()
271
return nil
272
}
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/lumberjack_test.go
renamed
+17
@@ -41,6 +41,7 @@ func TestNewFile(t *testing.T) {
41
n, err := l.Write(b)
42
isNil(err, t)
43
equals(len(b), n, t)
44
+ isNil(l.bw.Flush(), t)
45
existsWithLen(logFile(dir), n, t)
46
fileCount(dir, 1, t)
47
}
@@ -65,6 +66,7 @@ func TestOpenExisting(t *testing.T) {
66
isNil(err, t)
67
equals(len(b), n, t)
68
69
+ isNil(l.bw.Flush(), t)
70
// make sure the file got appended
71
existsWithLen(filename, len(data)+n, t)
72
@@ -106,6 +108,7 @@ func TestMakeLogDir(t *testing.T) {
108
n, err := l.Write(b)
109
isNil(err, t)
110
equals(len(b), n, t)
111
+ isNil(l.bw.Flush(), t)
112
existsWithLen(logFile(dir), n, t)
113
fileCount(dir, 1, t)
114
}
@@ -122,6 +125,7 @@ func TestDefaultFilename(t *testing.T) {
125
126
isNil(err, t)
127
equals(len(b), n, t)
128
+ isNil(l.bw.Flush(), t)
129
existsWithLen(filename, n, t)
130
}
131
@@ -142,6 +146,7 @@ func TestAutoRotate(t *testing.T) {
146
n, err := l.Write(b)
147
isNil(err, t)
148
equals(len(b), n, t)
149
+ isNil(l.bw.Flush(), t)
150
151
existsWithLen(filename, n, t)
152
fileCount(dir, 1, t)
@@ -152,6 +157,7 @@ func TestAutoRotate(t *testing.T) {
157
n, err = l.Write(b2)
158
isNil(err, t)
159
equals(len(b2), n, t)
160
+ isNil(l.bw.Flush(), t)
161
162
// the old logfile should be moved aside and the main logfile should have
163
// only the last write in it.
@@ -187,6 +193,7 @@ func TestFirstWriteRotate(t *testing.T) {
193
n, err := l.Write(b)
194
isNil(err, t)
195
equals(len(b), n, t)
196
+ isNil(l.bw.Flush(), t)
197
198
existsWithLen(filename, n, t)
199
existsWithLen(backupFile(dir), len(start), t)
@@ -211,6 +218,7 @@ func TestMaxBackups(t *testing.T) {
218
n, err := l.Write(b)
219
isNil(err, t)
220
equals(len(b), n, t)
221
+ isNil(l.bw.Flush(), t)
222
223
existsWithLen(filename, n, t)
224
fileCount(dir, 1, t)
@@ -222,6 +230,7 @@ func TestMaxBackups(t *testing.T) {
230
n, err = l.Write(b2)
231
isNil(err, t)
232
equals(len(b2), n, t)
233
+ isNil(l.bw.Flush(), t)
234
235
// this will use the new fake time
236
secondFilename := backupFile(dir)
@@ -238,6 +247,7 @@ func TestMaxBackups(t *testing.T) {
247
n, err = l.Write(b2)
248
isNil(err, t)
249
equals(len(b2), n, t)
250
+ isNil(l.bw.Flush(), t)
251
252
// this will use the new fake time
253
thirdFilename := backupFile(dir)
@@ -280,6 +290,7 @@ func TestMaxBackups(t *testing.T) {
290
n, err = l.Write(b2)
291
isNil(err, t)
292
equals(len(b2), n, t)
293
+ isNil(l.bw.Flush(), t)
294
295
// this will use the new fake time
296
fourthFilename := backupFile(dir)
@@ -326,6 +337,7 @@ func TestMaxAge(t *testing.T) {
337
n, err := l.Write(b)
338
isNil(err, t)
339
equals(len(b), n, t)
340
+ isNil(l.bw.Flush(), t)
341
342
existsWithLen(filename, n, t)
343
fileCount(dir, 1, t)
@@ -337,6 +349,7 @@ func TestMaxAge(t *testing.T) {
349
n, err = l.Write(b2)
350
isNil(err, t)
351
equals(len(b2), n, t)
352
+ isNil(l.bw.Flush(), t)
353
existsWithLen(backupFile(dir), len(b), t)
354
355
// we need to wait a little bit since the files get deleted on a different
@@ -359,6 +372,7 @@ func TestMaxAge(t *testing.T) {
372
n, err = l.Write(b2)
373
isNil(err, t)
374
equals(len(b3), n, t)
375
+ isNil(l.bw.Flush(), t)
376
existsWithLen(backupFile(dir), len(b2), t)
377
378
// we need to wait a little bit since the files get deleted on a different
@@ -454,6 +468,7 @@ func TestLocalTime(t *testing.T) {
468
n2, err := l.Write(b2)
469
isNil(err, t)
470
equals(len(b2), n2, t)
471
+ isNil(l.bw.Flush(), t)
472
473
existsWithLen(logFile(dir), n2, t)
474
existsWithLen(backupFileLocal(dir), n, t)
@@ -476,6 +491,7 @@ func TestRotate(t *testing.T) {
491
n, err := l.Write(b)
492
isNil(err, t)
493
equals(len(b), n, t)
494
+ isNil(l.bw.Flush(), t)
495
496
existsWithLen(filename, n, t)
497
fileCount(dir, 1, t)
@@ -511,6 +527,7 @@ func TestRotate(t *testing.T) {
527
n, err = l.Write(b2)
528
isNil(err, t)
529
equals(len(b2), n, t)
530
+ isNil(l.Close(), t)
531
532
// this will use the new fake time
533
existsWithLen(filename, n, t)
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/rotate_test.go
renamed
Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2/testing_test.go
renamed
thirdparty/eventlog/option.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"os"
6
7
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus"
8
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2"
8
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/gopkg.in/cryptix/lumberjack.v2"
9
)
10
11
// init sets up sane defaults