forked from TrueCloudLab/frostfs-node
Airat Arifullin
221203beeb
* Replace panics in unit tests by require.NoError and t.Fatalf Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
36 lines
713 B
Go
36 lines
713 B
Go
package test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
const sampling = 1000
|
|
|
|
// NewLogger creates a new logger.
|
|
//
|
|
// If debug, development logger is created.
|
|
func NewLogger(t testing.TB, debug bool) *logger.Logger {
|
|
var l logger.Logger
|
|
l.Logger = zap.L()
|
|
|
|
if debug {
|
|
cfg := zap.NewDevelopmentConfig()
|
|
cfg.Sampling = &zap.SamplingConfig{
|
|
Initial: sampling,
|
|
Thereafter: sampling,
|
|
}
|
|
|
|
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
|
|
|
log, err := cfg.Build()
|
|
require.NoError(t, err, "could not prepare logger")
|
|
l.Logger = log
|
|
}
|
|
|
|
return &l
|
|
}
|