mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
use forked lumberjack (buffers writes)
This commit is contained in:
10
Godeps/Godeps.json
generated
10
Godeps/Godeps.json
generated
@ -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"
|
||||
|
@ -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
|
||||
}
|
@ -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)
|
2
thirdparty/eventlog/option.go
vendored
2
thirdparty/eventlog/option.go
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user