diff --git a/dialer.go b/dialer.go index ca22da9..fc7e538 100644 --- a/dialer.go +++ b/dialer.go @@ -34,15 +34,10 @@ func (df dialerFunctionWrapper) Call() (serverConn, string, error) { // value), and adding a new network type is as easy as writing the dialer // function and adding it to the map. func (w *Writer) getDialer() dialerFunctionWrapper { - if w.customDial != nil { - // we use 'customDialer' as the name, since the custom dialer can technically - // override any network we pass in anyways - return dialerFunctionWrapper{"customDialer", w.customDialer} - } - dialers := map[string]dialerFunctionWrapper{ "": dialerFunctionWrapper{"unixDialer", w.unixDialer}, "tcp+tls": dialerFunctionWrapper{"tlsDialer", w.tlsDialer}, + "custom": dialerFunctionWrapper{"customDialer", w.customDialer}, } dialer, ok := dialers[w.network] if !ok { diff --git a/dialer_test.go b/dialer_test.go index cc36359..36490d1 100644 --- a/dialer_test.go +++ b/dialer_test.go @@ -47,6 +47,7 @@ func TestGetDialer(t *testing.T) { t.Errorf("should get basicDialer, got: %v", dialer) } + w.network = "custom" w.customDial = func(string, string) (net.Conn, error) { return nil, nil } dialer = w.getDialer() if "customDialer" != dialer.Name { @@ -209,10 +210,7 @@ func TestCustomDialer(t *testing.T) { // A custom dialer can really be anything, so we don't test an actual connection // instead we test the behavior of this code path - // a dialer implementation may still consult the passed network and address - // so make sure we don't change them before being passed in - - nwork, addr := "custom_network_to_pass", "custom_addr_to_pass" + nwork, addr := "custom", "custom_addr_to_pass" w := Writer{ priority: LOG_ERR, tag: "tag", diff --git a/srslog.go b/srslog.go index 5b8e38f..b47ad72 100644 --- a/srslog.go +++ b/srslog.go @@ -43,6 +43,7 @@ var ErrNilDialFunc = errors.New("srslog: nil DialFunc passed to DialWithCustomDi // DialWithCustomDialer establishes a connection by calling customDial. // Each write to the returned Writer sends a log message with the given facility, severity and tag. +// Network must be "custom" in order for this package to use customDial. // While network and raddr will be passed to customDial, it is allowed for customDial to ignore them. // If customDial is nil, this function returns ErrNilDialFunc. func DialWithCustomDialer(network, raddr string, priority Priority, tag string, customDial DialFunc) (*Writer, error) {