[TASK] show service of log-message

This commit is contained in:
Martin Geno 2017-08-30 09:10:56 +02:00
parent 5e453e234d
commit 14f3b40235
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
2 changed files with 21 additions and 2 deletions

View File

@ -51,10 +51,19 @@ func (n *Notifier) Send(e *log.Entry) {
format = "%s [%s]" format = "%s [%s]"
v = append(v, color.LightBlue(time.Now().Format(n.TimeFormat))) v = append(v, color.LightBlue(time.Now().Format(n.TimeFormat)))
} }
if e.Hostname != "" {
// Hostname and Service
if e.Hostname != "" && e.Service != "" {
format = fmt.Sprintf("%s [%%s-%%s]", format)
v = append(v, color.Purple(e.Hostname), color.Cyan(e.Service))
} else if e.Hostname != "" {
format = fmt.Sprintf("%s [%%s]", format) format = fmt.Sprintf("%s [%%s]", format)
v = append(v, color.Purple(e.Hostname)) v = append(v, color.Purple(e.Hostname))
} else if e.Service != "" {
format = fmt.Sprintf("%s [%%s]", format)
v = append(v, color.Cyan(e.Service))
} }
format = fmt.Sprintf("%s %%s", format) format = fmt.Sprintf("%s %%s", format)
lvl := e.Level.String() lvl := e.Level.String()
switch e.Level { switch e.Level {

View File

@ -7,5 +7,15 @@ import (
) )
func formatEntry(e *log.Entry) string { func formatEntry(e *log.Entry) string {
if e.Hostname != "" && e.Service != "" {
return fmt.Sprintf("[%s-%s] [%s] %s", e.Hostname, e.Service, e.Level, e.Text)
} else if e.Hostname != "" {
return fmt.Sprintf("[%s] [%s] %s", e.Hostname, e.Level, e.Text) return fmt.Sprintf("[%s] [%s] %s", e.Hostname, e.Level, e.Text)
} else if e.Service != "" {
return fmt.Sprintf("[%s] [%s] %s", e.Service, e.Level, e.Text)
}
return fmt.Sprintf("[%s] %s", e.Level, e.Text)
} }