1// Copyright 2016-2017 VMware, Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// +build !windows,!nacl,!plan9
16
17package syslog
18
19import (
20	"errors"
21	"net"
22)
23
24type unixSyslogDialer struct{}
25
26// unixSyslog opens a connection to the syslog daemon running on the
27// local machine using a Unix domain socket.
28func (u *unixSyslogDialer) dial() (net.Conn, error) {
29	logTypes := []string{"unixgram", "unix"}
30	logPaths := []string{"/dev/log", "/var/run/syslog", "/var/run/log"}
31	for _, network := range logTypes {
32		for _, path := range logPaths {
33			conn, err := net.Dial(network, path)
34			if err != nil {
35				continue
36			} else {
37				return conn, nil
38			}
39		}
40	}
41	return nil, errors.New("Unix syslog delivery error")
42}
43
44func newNetDialer(network, address string) netDialer {
45	if network == "" {
46		return &unixSyslogDialer{}
47	}
48
49	return &defaultNetDialer{
50		network: network,
51		address: address,
52	}
53}
54