Include timestamp offset in test message logger
This commit is contained in:
parent
c0ddd24dde
commit
e3d4fc5a8e
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@ -17,6 +18,20 @@ func MarkIntegrationTest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type mlogMessageHandlerWithOffset struct {
|
||||
mlog.MessageHandler
|
||||
start time.Time
|
||||
}
|
||||
|
||||
func (h *mlogMessageHandlerWithOffset) Handle(msg mlog.FullMessage) error {
|
||||
msg.Description = fmt.Sprintf(
|
||||
"(+%v) %s",
|
||||
time.Since(h.start).Truncate(time.Millisecond),
|
||||
msg.Description,
|
||||
)
|
||||
return h.MessageHandler.Handle(msg)
|
||||
}
|
||||
|
||||
// NewTestLogger returns a Logger which should be used for testing purposes. The
|
||||
// log level of the Logger can be adjusted using the ISLE_LOG_LEVEL envvar.
|
||||
func NewTestLogger(t *testing.T) *mlog.Logger {
|
||||
@ -27,8 +42,14 @@ func NewTestLogger(t *testing.T) *mlog.Logger {
|
||||
}
|
||||
}
|
||||
|
||||
handler := mlog.NewTestMessageHandler(t)
|
||||
handler = &mlogMessageHandlerWithOffset{
|
||||
MessageHandler: handler,
|
||||
start: time.Now(),
|
||||
}
|
||||
|
||||
return mlog.NewLogger(&mlog.LoggerOpts{
|
||||
MessageHandler: mlog.NewTestMessageHandler(t),
|
||||
MessageHandler: handler,
|
||||
MaxLevel: level.Int(),
|
||||
})
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
---
|
||||
type: task
|
||||
---
|
||||
|
||||
On each message which is logged the test message logger (toolkit.NewTestLogger)
|
||||
should include the duration since then the test started.
|
Loading…
Reference in New Issue
Block a user