Skip to content

Commit 47ffae2

Browse files
authored
cleanup and module support (#77)
* cleanup and module support
1 parent 94d9e49 commit 47ffae2

File tree

8 files changed

+45
-30
lines changed

8 files changed

+45
-30
lines changed

.travis.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
language: go
22

33
go:
4-
- 1.8
5-
- 1.7
6-
- 1.6
4+
- tip
5+
- 1.15.x
6+
- 1.14.x
7+
- 1.13.x
8+
- 1.12.x
9+
10+
env:
11+
- GO111MODULE=on

chown_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"syscall"
66
)
77

8-
// os_Chown is a var so we can mock it out during tests.
9-
var os_Chown = os.Chown
8+
// osChown is a var so we can mock it out during tests.
9+
var osChown = os.Chown
1010

1111
func chown(name string, info os.FileInfo) error {
1212
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 {
1515
}
1616
f.Close()
1717
stat := info.Sys().(*syscall.Stat_t)
18-
return os_Chown(name, int(stat.Uid), int(stat.Gid))
18+
return osChown(name, int(stat.Uid), int(stat.Gid))
1919
}

example_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
package lumberjack_test
1+
package lumberjack
22

33
import (
44
"log"
5-
6-
"gopkg.in/natefinch/lumberjack.v2"
75
)
86

97
// To use lumberjack with the standard library's log package, just pass it into
108
// the SetOutput function when your application starts.
119
func Example() {
12-
log.SetOutput(&lumberjack.Logger{
10+
log.SetOutput(&Logger{
1311
Filename: "/var/log/myapp/foo.log",
1412
MaxSize: 500, // megabytes
1513
MaxBackups: 3,
16-
MaxAge: 28, // days
14+
MaxAge: 28, // days
1715
Compress: true, // disabled by default
1816
})
1917
}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/natefinch/lumberjack
2+
3+
require (
4+
github.com/BurntSushi/toml v0.3.1
5+
gopkg.in/yaml.v2 v2.2.2
6+
)
7+
8+
go 1.13

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
6+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

linux_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func TestMaintainMode(t *testing.T) {
4848

4949
func TestMaintainOwner(t *testing.T) {
5050
fakeFS := newFakeFS()
51-
os_Chown = fakeFS.Chown
52-
os_Stat = fakeFS.Stat
51+
osChown = fakeFS.Chown
52+
osStat = fakeFS.Stat
5353
defer func() {
54-
os_Chown = os.Chown
55-
os_Stat = os.Stat
54+
osChown = os.Chown
55+
osStat = os.Stat
5656
}()
5757
currentTime = fakeTime
5858
dir := makeTempDir("TestMaintainOwner", t)
@@ -98,7 +98,7 @@ func TestCompressMaintainMode(t *testing.T) {
9898
f.Close()
9999

100100
l := &Logger{
101-
Compress: true,
101+
Compress: true,
102102
Filename: filename,
103103
MaxBackups: 1,
104104
MaxSize: 100, // megabytes
@@ -123,19 +123,19 @@ func TestCompressMaintainMode(t *testing.T) {
123123
filename2 := backupFile(dir)
124124
info, err := os.Stat(filename)
125125
isNil(err, t)
126-
info2, err := os.Stat(filename2+compressSuffix)
126+
info2, err := os.Stat(filename2 + compressSuffix)
127127
isNil(err, t)
128128
equals(mode, info.Mode(), t)
129129
equals(mode, info2.Mode(), t)
130130
}
131131

132132
func TestCompressMaintainOwner(t *testing.T) {
133133
fakeFS := newFakeFS()
134-
os_Chown = fakeFS.Chown
135-
os_Stat = fakeFS.Stat
134+
osChown = fakeFS.Chown
135+
osStat = fakeFS.Stat
136136
defer func() {
137-
os_Chown = os.Chown
138-
os_Stat = os.Stat
137+
osChown = os.Chown
138+
osStat = os.Stat
139139
}()
140140
currentTime = fakeTime
141141
dir := makeTempDir("TestCompressMaintainOwner", t)

lumberjack.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ var (
120120
currentTime = time.Now
121121

122122
// os_Stat exists so it can be mocked out by tests.
123-
os_Stat = os.Stat
123+
osStat = os.Stat
124124

125125
// megabyte is the conversion factor between MaxSize and bytes. It is a
126126
// variable so tests can mock it out and not need to write megabytes of data
@@ -213,7 +213,7 @@ func (l *Logger) openNew() error {
213213

214214
name := l.filename()
215215
mode := os.FileMode(0600)
216-
info, err := os_Stat(name)
216+
info, err := osStat(name)
217217
if err == nil {
218218
// Copy the mode off the old logfile.
219219
mode = info.Mode()
@@ -265,7 +265,7 @@ func (l *Logger) openExistingOrNew(writeLen int) error {
265265
l.mill()
266266

267267
filename := l.filename()
268-
info, err := os_Stat(filename)
268+
info, err := osStat(filename)
269269
if os.IsNotExist(err) {
270270
return l.openNew()
271271
}
@@ -376,7 +376,7 @@ func (l *Logger) millRunOnce() error {
376376
// millRun runs in a goroutine to manage post-rotation compression and removal
377377
// of old log files.
378378
func (l *Logger) millRun() {
379-
for _ = range l.millCh {
379+
for range l.millCh {
380380
// what am I going to do, log this?
381381
_ = l.millRunOnce()
382382
}
@@ -472,7 +472,7 @@ func compressLogFile(src, dst string) (err error) {
472472
}
473473
defer f.Close()
474474

475-
fi, err := os_Stat(src)
475+
fi, err := osStat(src)
476476
if err != nil {
477477
return fmt.Errorf("failed to stat log file: %v", err)
478478
}

rotate_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
// +build linux
22

3-
package lumberjack_test
3+
package lumberjack
44

55
import (
66
"log"
77
"os"
88
"os/signal"
99
"syscall"
10-
11-
"gopkg.in/natefinch/lumberjack.v2"
1210
)
1311

1412
// Example of how to rotate in response to SIGHUP.
1513
func ExampleLogger_Rotate() {
16-
l := &lumberjack.Logger{}
14+
l := &Logger{}
1715
log.SetOutput(l)
1816
c := make(chan os.Signal, 1)
1917
signal.Notify(c, syscall.SIGHUP)

0 commit comments

Comments
 (0)