mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package prefixed_test
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/pkg/errors"
|
|
. "github.com/prysmaticlabs/prysm/v3/runtime/logging/logrus-prefixed-formatter"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var _ = Describe("Formatter", func() {
|
|
var formatter *TextFormatter
|
|
var log *logrus.Logger
|
|
var output *LogOutput
|
|
|
|
BeforeEach(func() {
|
|
output = new(LogOutput)
|
|
formatter = new(TextFormatter)
|
|
log = logrus.New()
|
|
log.Out = output
|
|
log.Formatter = formatter
|
|
log.Level = logrus.DebugLevel
|
|
})
|
|
|
|
Describe("logfmt output", func() {
|
|
It("should output simple message", func() {
|
|
formatter.DisableTimestamp = true
|
|
log.Debug("test")
|
|
Ω(output.GetValue()).Should(Equal("level=debug msg=test\n"))
|
|
})
|
|
|
|
It("should output message with additional field", func() {
|
|
formatter.DisableTimestamp = true
|
|
log.WithFields(logrus.Fields{"animal": "walrus"}).Debug("test")
|
|
Ω(output.GetValue()).Should(Equal("level=debug msg=test animal=walrus\n"))
|
|
})
|
|
})
|
|
|
|
Describe("Formatted output", func() {
|
|
It("should output formatted message", func() {
|
|
formatter.DisableTimestamp = true
|
|
formatter.ForceFormatting = true
|
|
log.Debug("test")
|
|
Ω(output.GetValue()).Should(Equal("DEBUG test\n"))
|
|
})
|
|
})
|
|
|
|
Describe("Theming support", func() {
|
|
|
|
})
|
|
})
|
|
|
|
func TestFormatter_SuppressErrorStackTraces(t *testing.T) {
|
|
formatter := new(TextFormatter)
|
|
formatter.ForceFormatting = true
|
|
log := logrus.New()
|
|
log.Formatter = formatter
|
|
output := new(LogOutput)
|
|
log.Out = output
|
|
|
|
errFn := func() error {
|
|
return errors.New("inner")
|
|
}
|
|
|
|
log.WithError(errors.Wrap(errFn(), "outer")).Error("test")
|
|
require.Equal(t, true, regexp.MustCompile(`test error=outer: inner\n\s*$`).MatchString(output.GetValue()), fmt.Sprintf("wrong log output: %s", output.GetValue()))
|
|
}
|
|
|
|
func TestFormatter_EscapesControlCharacters(t *testing.T) {
|
|
formatter := new(TextFormatter)
|
|
formatter.ForceFormatting = true
|
|
log := logrus.New()
|
|
log.Formatter = formatter
|
|
output := new(LogOutput)
|
|
log.Out = output
|
|
|
|
log.WithField("test", "foo\nbar").Error("testing things")
|
|
require.Equal(t, "[0000] ERROR testing things test=foobar"+"\n", output.GetValue())
|
|
}
|