(address string)
| 191 | } |
| 192 | |
| 193 | func parseSyslogAddress(address string) (string, string, error) { |
| 194 | if address == "" { |
| 195 | // Docker-compatible: fallback to `unix:///dev/log`, |
| 196 | // `unix:///var/run/syslog` or `unix:///var/run/log`. We do nothing |
| 197 | // with the empty address, just leave it here and the srslog will |
| 198 | // handle the fallback. |
| 199 | return "", "", nil |
| 200 | } |
| 201 | addr, err := url.Parse(address) |
| 202 | if err != nil { |
| 203 | return "", "", err |
| 204 | } |
| 205 | |
| 206 | // unix and unixgram socket validation |
| 207 | if addr.Scheme == "unix" || addr.Scheme == "unixgram" { |
| 208 | if _, err := os.Stat(addr.Path); err != nil { |
| 209 | return "", "", err |
| 210 | } |
| 211 | return addr.Scheme, addr.Path, nil |
| 212 | } |
| 213 | if addr.Scheme != "udp" && addr.Scheme != "tcp" && addr.Scheme != syslogSecureProto { |
| 214 | return "", "", fmt.Errorf("unsupported scheme: '%s'", addr.Scheme) |
| 215 | } |
| 216 | |
| 217 | // here we process tcp|udp |
| 218 | host := addr.Host |
| 219 | if _, _, err := net.SplitHostPort(host); err != nil { |
| 220 | if !strings.Contains(err.Error(), "missing port in address") { |
| 221 | return "", "", err |
| 222 | } |
| 223 | host = net.JoinHostPort(host, syslogDefaultPort) |
| 224 | } |
| 225 | |
| 226 | return addr.Scheme, host, nil |
| 227 | } |
| 228 | |
| 229 | func parseSyslogFacility(facility string) (syslog.Priority, error) { |
| 230 | if facility == "" { |
no test coverage detected
searching dependent graphs…