@@ -20,7 +20,14 @@ import (
2020 "github.com/gliderlabs/logspout/router"
2121)
2222
23- const defaultRetryCount = 10
23+ const (
24+ // TraditionalTCPFraming is the traditional LF framing of syslog messages on the wire
25+ TraditionalTCPFraming TCPFraming = "traditional"
26+ // OctetCountedTCPFraming prepends the size of each message before the message. https://tools.ietf.org/html/rfc6587#section-3.4.1
27+ OctetCountedTCPFraming TCPFraming = "octet-counted"
28+
29+ defaultRetryCount = 10
30+ )
2431
2532var (
2633 hostname string
3239// TCPFraming represents the type of framing to use for syslog messages
3340type TCPFraming string
3441
35- const (
36- // TraditionalTCPFraming is the traditional LF framing of syslog messages on the wire
37- TraditionalTCPFraming TCPFraming = "traditional"
38- // OctetCountedTCPFraming prepends the size of each message before the message. https://tools.ietf.org/html/rfc6587#section-3.4.1
39- OctetCountedTCPFraming TCPFraming = "octet-counted"
40- )
41-
4242func init () {
4343 hostname , _ = os .Hostname ()
4444 econnResetErrStr = fmt .Sprintf ("write: %s" , syscall .ECONNRESET .Error ())
@@ -102,13 +102,8 @@ func NewSyslogAdapter(route *router.Route) (router.LogAdapter, error) {
102102 }
103103
104104 if isTCPConnecion (conn ) {
105- switch s := cfg .GetEnvDefault ("SYSLOG_TCP_FRAMING" , "traditional" ); s {
106- case "traditional" :
107- tcpFraming = TraditionalTCPFraming
108- case "octet-counted" :
109- tcpFraming = OctetCountedTCPFraming
110- default :
111- return nil , fmt .Errorf ("unknown SYSLOG_TCP_FRAMING value: %s" , s )
105+ if err = setTCPFraming (); err != nil {
106+ return nil , err
112107 }
113108 }
114109
@@ -143,6 +138,19 @@ func NewSyslogAdapter(route *router.Route) (router.LogAdapter, error) {
143138 }, nil
144139}
145140
141+ func setTCPFraming () error {
142+ switch s := cfg .GetEnvDefault ("SYSLOG_TCP_FRAMING" , "traditional" ); s {
143+ case "traditional" :
144+ tcpFraming = TraditionalTCPFraming
145+ return nil
146+ case "octet-counted" :
147+ tcpFraming = OctetCountedTCPFraming
148+ return nil
149+ default :
150+ return fmt .Errorf ("unknown SYSLOG_TCP_FRAMING value: %s" , s )
151+ }
152+ }
153+
146154// Adapter streams log output to a connection in the Syslog format
147155type Adapter struct {
148156 conn net.Conn
0 commit comments