From 4f397006184f031e23c875284c3c1bd3b3e6b0ef Mon Sep 17 00:00:00 2001 From: Daniel Fuentes Date: Sat, 9 May 2015 17:37:59 -0700 Subject: [PATCH] Adds a .Env function on syslog messages: - This allows you to use docker container environment variables in the templates for things like SYSLOG_TAG --- adapters/syslog/syslog.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/adapters/syslog/syslog.go b/adapters/syslog/syslog.go index eb1b32a1..b0aa704c 100644 --- a/adapters/syslog/syslog.go +++ b/adapters/syslog/syslog.go @@ -9,6 +9,7 @@ import ( "net" "os" "reflect" + "strings" "text/template" "time" @@ -132,3 +133,13 @@ func (m *SyslogMessage) Timestamp() string { func (m *SyslogMessage) ContainerName() string { return m.Message.Container.Name[1:] } + +func (m *SyslogMessage) Env(key string) string { + envValues := m.Message.Container.Config.Env + for _, env := range envValues { + if strings.HasPrefix(env, key) { + return env[len(key)+1:] + } + } + return "" +}