2020-07-10 14:17:51 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2023-03-28 14:16:03 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2023-03-28 14:16:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-10 14:17:51 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const sampling = 1000
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// NewLogger creates a new logger.
|
|
|
|
//
|
|
|
|
// If debug, development logger is created.
|
2023-03-28 14:16:03 +00:00
|
|
|
func NewLogger(t testing.TB, debug bool) *logger.Logger {
|
2022-09-28 07:41:01 +00:00
|
|
|
var l logger.Logger
|
|
|
|
l.Logger = zap.L()
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
if debug {
|
|
|
|
cfg := zap.NewDevelopmentConfig()
|
|
|
|
cfg.Sampling = &zap.SamplingConfig{
|
|
|
|
Initial: sampling,
|
|
|
|
Thereafter: sampling,
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
|
|
|
|
|
|
|
log, err := cfg.Build()
|
2023-03-28 14:16:03 +00:00
|
|
|
require.NoError(t, err, "could not prepare logger")
|
2022-09-28 07:41:01 +00:00
|
|
|
l.Logger = log
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 07:41:01 +00:00
|
|
|
return &l
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|