|
|
@ -24,6 +24,10 @@ var (
|
|
|
|
_ Writer = (*mockWriter)(nil)
|
|
|
|
_ Writer = (*mockWriter)(nil)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
ExitOnFatal.Set(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type mockWriter struct {
|
|
|
|
type mockWriter struct {
|
|
|
|
lock sync.Mutex
|
|
|
|
lock sync.Mutex
|
|
|
|
builder strings.Builder
|
|
|
|
builder strings.Builder
|
|
|
@ -208,6 +212,12 @@ func TestFileLineConsoleMode(t *testing.T) {
|
|
|
|
assert.True(t, w.Contains(fmt.Sprintf("%s:%d", file, line+1)))
|
|
|
|
assert.True(t, w.Contains(fmt.Sprintf("%s:%d", file, line+1)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestMust(t *testing.T) {
|
|
|
|
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
|
|
|
|
Must(errors.New("foo"))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestStructedLogAlert(t *testing.T) {
|
|
|
|
func TestStructedLogAlert(t *testing.T) {
|
|
|
|
w := new(mockWriter)
|
|
|
|
w := new(mockWriter)
|
|
|
|
old := writer.Swap(w)
|
|
|
|
old := writer.Swap(w)
|
|
|
@ -574,26 +584,38 @@ func TestSetup(t *testing.T) {
|
|
|
|
atomic.StoreUint32(&encoding, jsonEncodingType)
|
|
|
|
atomic.StoreUint32(&encoding, jsonEncodingType)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setupOnce = sync.Once{}
|
|
|
|
|
|
|
|
MustSetup(LogConf{
|
|
|
|
|
|
|
|
ServiceName: "any",
|
|
|
|
|
|
|
|
Mode: "console",
|
|
|
|
|
|
|
|
Encoding: "json",
|
|
|
|
|
|
|
|
TimeFormat: timeFormat,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
setupOnce = sync.Once{}
|
|
|
|
MustSetup(LogConf{
|
|
|
|
MustSetup(LogConf{
|
|
|
|
ServiceName: "any",
|
|
|
|
ServiceName: "any",
|
|
|
|
Mode: "console",
|
|
|
|
Mode: "console",
|
|
|
|
TimeFormat: timeFormat,
|
|
|
|
TimeFormat: timeFormat,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
setupOnce = sync.Once{}
|
|
|
|
MustSetup(LogConf{
|
|
|
|
MustSetup(LogConf{
|
|
|
|
ServiceName: "any",
|
|
|
|
ServiceName: "any",
|
|
|
|
Mode: "file",
|
|
|
|
Mode: "file",
|
|
|
|
Path: os.TempDir(),
|
|
|
|
Path: os.TempDir(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
setupOnce = sync.Once{}
|
|
|
|
MustSetup(LogConf{
|
|
|
|
MustSetup(LogConf{
|
|
|
|
ServiceName: "any",
|
|
|
|
ServiceName: "any",
|
|
|
|
Mode: "volume",
|
|
|
|
Mode: "volume",
|
|
|
|
Path: os.TempDir(),
|
|
|
|
Path: os.TempDir(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
setupOnce = sync.Once{}
|
|
|
|
MustSetup(LogConf{
|
|
|
|
MustSetup(LogConf{
|
|
|
|
ServiceName: "any",
|
|
|
|
ServiceName: "any",
|
|
|
|
Mode: "console",
|
|
|
|
Mode: "console",
|
|
|
|
TimeFormat: timeFormat,
|
|
|
|
TimeFormat: timeFormat,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
setupOnce = sync.Once{}
|
|
|
|
MustSetup(LogConf{
|
|
|
|
MustSetup(LogConf{
|
|
|
|
ServiceName: "any",
|
|
|
|
ServiceName: "any",
|
|
|
|
Mode: "console",
|
|
|
|
Mode: "console",
|
|
|
|