forked from natefinch/lumberjack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
34 lines (28 loc) · 878 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//nolint:testpackage // use same name as package to access variables to mock
package woodcutter
import (
"log"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
// To use woodcutter with the standard library's log package, just pass it into
// the SetOutput function when your application starts.
func TestExample_UsageWithStandardLogger(t *testing.T) {
cwd := t.TempDir()
logfilename := filepath.Join(cwd, "foo.log")
woodcutterlogger := Logger{
Filename: logfilename,
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, // days
Compress: true, // disabled by default
}
log.SetOutput(&woodcutterlogger)
defer woodcutterlogger.Close()
logger := log.Default()
content := "test logging with standard logger"
logger.Printf(content)
assert.FileExists(t, logfilename)
fileContainsContent(t, logfilename, []byte(content))
}