// NewReplicator returns a new Replicator instance that makes calls with the given // SubChannel to the service defined by SubChannel.GetServiceName(). The given n/w/r // values will be used as defaults for the replicator when none are provided // Deprecation: logger is no longer used. func NewReplicator(s Sender, channel shared.SubChannel, logger log.Logger, opts *Options) *Replicator { f := forward.NewForwarder(s, channel) opts = mergeDefaultOptions(opts, &Options{3, 1, 3, Parallel}) logger = logging.Logger("replicator") if identity, err := s.WhoAmI(); err == nil { logger = logger.WithField("local", identity) } return &Replicator{s, channel, f, logger, opts} }
func TestGetFields(t *testing.T) { var logger bark.Logger // Plain logger logger = bark.NewLoggerFromLogrus(logrus.New()) require.Equal(t, logger.Fields(), bark.Fields(nil)) // Add nil, don't crash logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithFields(nil) require.Equal(t, logger.Fields(), bark.Fields(nil)) // One field added logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithField("foo", "bar") require.Equal(t, logger.Fields(), bark.Fields{"foo": "bar"}) // Two fields added at once logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithFields(bark.Fields{"foo": "bar", "baz": "bump"}) require.Equal(t, logger.Fields(), bark.Fields{"foo": "bar", "baz": "bump"}) // One then one logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithField("foo", "bar") logger = logger.WithField("baz", "bump") require.Equal(t, logger.Fields(), bark.Fields{"foo": "bar", "baz": "bump"}) // Two then one logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithFields(bark.Fields{"foo": "bar", "baz": "bump"}) logger = logger.WithField("x", "y") require.Equal(t, logger.Fields(), bark.Fields{"foo": "bar", "baz": "bump", "x": "y"}) // One then two logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithField("x", "y") logger = logger.WithFields(bark.Fields{"foo": "bar", "baz": "bump"}) require.Equal(t, logger.Fields(), bark.Fields{"foo": "bar", "baz": "bump", "x": "y"}) // Two then two logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithFields(bark.Fields{"foo": "bar", "baz": "bump"}) logger = logger.WithFields(bark.Fields{"a": "b", "c": "d"}) require.Equal(t, logger.Fields(), bark.Fields{"foo": "bar", "baz": "bump", "a": "b", "c": "d"}) // Add empty map logger = bark.NewLoggerFromLogrus(logrus.New()) logger = logger.WithFields(bark.Fields{}) require.Equal(t, logger.Fields(), bark.Fields{}) }