|
@@ -6,6 +6,7 @@ import (
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"log"
|
|
"log"
|
|
|
|
+ "os"
|
|
"runtime"
|
|
"runtime"
|
|
"strings"
|
|
"strings"
|
|
"sync/atomic"
|
|
"sync/atomic"
|
|
@@ -175,6 +176,43 @@ func TestMustNil(t *testing.T) {
|
|
Must(nil)
|
|
Must(nil)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestSetup(t *testing.T) {
|
|
|
|
+ MustSetup(LogConf{
|
|
|
|
+ ServiceName: "any",
|
|
|
|
+ Mode: "console",
|
|
|
|
+ })
|
|
|
|
+ MustSetup(LogConf{
|
|
|
|
+ ServiceName: "any",
|
|
|
|
+ Mode: "file",
|
|
|
|
+ Path: os.TempDir(),
|
|
|
|
+ })
|
|
|
|
+ MustSetup(LogConf{
|
|
|
|
+ ServiceName: "any",
|
|
|
|
+ Mode: "volume",
|
|
|
|
+ Path: os.TempDir(),
|
|
|
|
+ })
|
|
|
|
+ assert.NotNil(t, setupWithVolume(LogConf{}))
|
|
|
|
+ assert.NotNil(t, setupWithFiles(LogConf{}))
|
|
|
|
+ assert.Nil(t, setupWithFiles(LogConf{
|
|
|
|
+ ServiceName: "any",
|
|
|
|
+ Path: os.TempDir(),
|
|
|
|
+ Compress: true,
|
|
|
|
+ KeepDays: 1,
|
|
|
|
+ }))
|
|
|
|
+ setupLogLevel(LogConf{
|
|
|
|
+ Level: levelInfo,
|
|
|
|
+ })
|
|
|
|
+ setupLogLevel(LogConf{
|
|
|
|
+ Level: levelError,
|
|
|
|
+ })
|
|
|
|
+ setupLogLevel(LogConf{
|
|
|
|
+ Level: levelSevere,
|
|
|
|
+ })
|
|
|
|
+ _, err := createOutput("")
|
|
|
|
+ assert.NotNil(t, err)
|
|
|
|
+ Disable()
|
|
|
|
+}
|
|
|
|
+
|
|
func TestDisable(t *testing.T) {
|
|
func TestDisable(t *testing.T) {
|
|
Disable()
|
|
Disable()
|
|
WithKeepDays(1)
|
|
WithKeepDays(1)
|
|
@@ -184,6 +222,20 @@ func TestDisable(t *testing.T) {
|
|
assert.Nil(t, Close())
|
|
assert.Nil(t, Close())
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestWithGzip(t *testing.T) {
|
|
|
|
+ fn := WithGzip()
|
|
|
|
+ var opt logOptions
|
|
|
|
+ fn(&opt)
|
|
|
|
+ assert.True(t, opt.gzipEnabled)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestWithKeepDays(t *testing.T) {
|
|
|
|
+ fn := WithKeepDays(1)
|
|
|
|
+ var opt logOptions
|
|
|
|
+ fn(&opt)
|
|
|
|
+ assert.Equal(t, 1, opt.keepDays)
|
|
|
|
+}
|
|
|
|
+
|
|
func BenchmarkCopyByteSliceAppend(b *testing.B) {
|
|
func BenchmarkCopyByteSliceAppend(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
for i := 0; i < b.N; i++ {
|
|
var buf []byte
|
|
var buf []byte
|
|
@@ -301,4 +353,10 @@ func testSetLevelTwiceWithMode(t *testing.T, mode string) {
|
|
atomic.StoreUint32(&initialized, 1)
|
|
atomic.StoreUint32(&initialized, 1)
|
|
Info(message)
|
|
Info(message)
|
|
assert.Equal(t, 0, writer.builder.Len())
|
|
assert.Equal(t, 0, writer.builder.Len())
|
|
|
|
+ Infof(message)
|
|
|
|
+ assert.Equal(t, 0, writer.builder.Len())
|
|
|
|
+ ErrorStack(message)
|
|
|
|
+ assert.Equal(t, 0, writer.builder.Len())
|
|
|
|
+ ErrorStackf(message)
|
|
|
|
+ assert.Equal(t, 0, writer.builder.Len())
|
|
}
|
|
}
|