@@ -10,6 +10,7 @@ import (
1010 "net"
1111 "os"
1212 "strconv"
13+ "strings"
1314 "syscall"
1415 "text/template"
1516 "time"
@@ -55,6 +56,16 @@ func debug(v ...interface{}) {
5556 }
5657}
5758
59+ func getHostname () string {
60+ content , err := ioutil .ReadFile ("/etc/host_hostname" )
61+ if err == nil && len (content ) > 0 {
62+ hostname = strings .TrimRight (string (content ), "\r \n " )
63+ } else {
64+ hostname = getopt ("SYSLOG_HOSTNAME" , "{{.Container.Config.Hostname}}" )
65+ }
66+ return hostname
67+ }
68+
5869// NewSyslogAdapter returnas a configured syslog.Adapter
5970func NewSyslogAdapter (route * router.Route ) (router.LogAdapter , error ) {
6071 transport , found := router .AdapterTransports .Lookup (route .AdapterTransport ("udp" ))
@@ -69,13 +80,8 @@ func NewSyslogAdapter(route *router.Route) (router.LogAdapter, error) {
6980 format := getopt ("SYSLOG_FORMAT" , "rfc5424" )
7081 priority := getopt ("SYSLOG_PRIORITY" , "{{.Priority}}" )
7182 pid := getopt ("SYSLOG_PID" , "{{.Container.State.Pid}}" )
83+ hostname = getHostname ()
7284
73- content , err := ioutil .ReadFile ("/etc/host_hostname" ) // just pass the file name
74- if err == nil && len (content ) > 0 {
75- hostname = string (content ) // convert content to a 'string'
76- } else {
77- hostname = getopt ("SYSLOG_HOSTNAME" , "{{.Container.Config.Hostname}}" )
78- }
7985 tag := getopt ("SYSLOG_TAG" , "{{.ContainerName}}" + route .Options ["append_tag" ])
8086 structuredData := getopt ("SYSLOG_STRUCTURED_DATA" , "" )
8187 if route .Options ["structured_data" ] != "" {
0 commit comments