diff --git a/.travis.yml b/.travis.yml index 65dcbc5..21166f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ language: go go: - - 1.8 - - 1.7 - - 1.6 \ No newline at end of file + - tip + - 1.15.x + - 1.14.x + - 1.13.x + - 1.12.x + +env: + - GO111MODULE=on diff --git a/chown_linux.go b/chown_linux.go index 2758ec9..465f569 100644 --- a/chown_linux.go +++ b/chown_linux.go @@ -5,8 +5,8 @@ import ( "syscall" ) -// os_Chown is a var so we can mock it out during tests. -var os_Chown = os.Chown +// osChown is a var so we can mock it out during tests. +var osChown = os.Chown func chown(name string, info os.FileInfo) error { f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode()) @@ -15,5 +15,5 @@ func chown(name string, info os.FileInfo) error { } f.Close() stat := info.Sys().(*syscall.Stat_t) - return os_Chown(name, int(stat.Uid), int(stat.Gid)) + return osChown(name, int(stat.Uid), int(stat.Gid)) } diff --git a/example_test.go b/example_test.go index df3dfb2..1da21e6 100644 --- a/example_test.go +++ b/example_test.go @@ -1,19 +1,17 @@ -package lumberjack_test +package lumberjack import ( "log" - - "gopkg.in/natefinch/lumberjack.v2" ) // To use lumberjack with the standard library's log package, just pass it into // the SetOutput function when your application starts. func Example() { - log.SetOutput(&lumberjack.Logger{ + log.SetOutput(&Logger{ Filename: "/var/log/myapp/foo.log", MaxSize: 500, // megabytes MaxBackups: 3, - MaxAge: 28, // days + MaxAge: 28, // days Compress: true, // disabled by default }) } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9061bae --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/natefinch/lumberjack + +require ( + github.com/BurntSushi/toml v0.3.1 + gopkg.in/yaml.v2 v2.2.2 +) + +go 1.13 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a2ea702 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/linux_test.go b/linux_test.go index 2bd1684..61dff04 100644 --- a/linux_test.go +++ b/linux_test.go @@ -48,11 +48,11 @@ func TestMaintainMode(t *testing.T) { func TestMaintainOwner(t *testing.T) { fakeFS := newFakeFS() - os_Chown = fakeFS.Chown - os_Stat = fakeFS.Stat + osChown = fakeFS.Chown + osStat = fakeFS.Stat defer func() { - os_Chown = os.Chown - os_Stat = os.Stat + osChown = os.Chown + osStat = os.Stat }() currentTime = fakeTime dir := makeTempDir("TestMaintainOwner", t) @@ -98,7 +98,7 @@ func TestCompressMaintainMode(t *testing.T) { f.Close() l := &Logger{ - Compress: true, + Compress: true, Filename: filename, MaxBackups: 1, MaxSize: 100, // megabytes @@ -123,7 +123,7 @@ func TestCompressMaintainMode(t *testing.T) { filename2 := backupFile(dir) info, err := os.Stat(filename) isNil(err, t) - info2, err := os.Stat(filename2+compressSuffix) + info2, err := os.Stat(filename2 + compressSuffix) isNil(err, t) equals(mode, info.Mode(), t) equals(mode, info2.Mode(), t) @@ -131,11 +131,11 @@ func TestCompressMaintainMode(t *testing.T) { func TestCompressMaintainOwner(t *testing.T) { fakeFS := newFakeFS() - os_Chown = fakeFS.Chown - os_Stat = fakeFS.Stat + osChown = fakeFS.Chown + osStat = fakeFS.Stat defer func() { - os_Chown = os.Chown - os_Stat = os.Stat + osChown = os.Chown + osStat = os.Stat }() currentTime = fakeTime dir := makeTempDir("TestCompressMaintainOwner", t) diff --git a/lumberjack.go b/lumberjack.go index a47b7f0..3447cdc 100644 --- a/lumberjack.go +++ b/lumberjack.go @@ -120,7 +120,7 @@ var ( currentTime = time.Now // os_Stat exists so it can be mocked out by tests. - os_Stat = os.Stat + osStat = os.Stat // megabyte is the conversion factor between MaxSize and bytes. It is a // variable so tests can mock it out and not need to write megabytes of data @@ -213,7 +213,7 @@ func (l *Logger) openNew() error { name := l.filename() mode := os.FileMode(0600) - info, err := os_Stat(name) + info, err := osStat(name) if err == nil { // Copy the mode off the old logfile. mode = info.Mode() @@ -265,7 +265,7 @@ func (l *Logger) openExistingOrNew(writeLen int) error { l.mill() filename := l.filename() - info, err := os_Stat(filename) + info, err := osStat(filename) if os.IsNotExist(err) { return l.openNew() } @@ -376,7 +376,7 @@ func (l *Logger) millRunOnce() error { // millRun runs in a goroutine to manage post-rotation compression and removal // of old log files. func (l *Logger) millRun() { - for _ = range l.millCh { + for range l.millCh { // what am I going to do, log this? _ = l.millRunOnce() } @@ -472,7 +472,7 @@ func compressLogFile(src, dst string) (err error) { } defer f.Close() - fi, err := os_Stat(src) + fi, err := osStat(src) if err != nil { return fmt.Errorf("failed to stat log file: %v", err) } diff --git a/rotate_test.go b/rotate_test.go index 4bd4325..453bf14 100644 --- a/rotate_test.go +++ b/rotate_test.go @@ -1,19 +1,17 @@ // +build linux -package lumberjack_test +package lumberjack import ( "log" "os" "os/signal" "syscall" - - "gopkg.in/natefinch/lumberjack.v2" ) // Example of how to rotate in response to SIGHUP. func ExampleLogger_Rotate() { - l := &lumberjack.Logger{} + l := &Logger{} log.SetOutput(l) c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGHUP)