From 14f3b4023543ba47c734336d921879e4d0732cca Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Wed, 30 Aug 2017 09:10:56 +0200 Subject: [PATCH] [TASK] show service of log-message --- notify/console/main.go | 11 ++++++++++- notify/xmpp/internal.go | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/notify/console/main.go b/notify/console/main.go index ab12f25..1110826 100644 --- a/notify/console/main.go +++ b/notify/console/main.go @@ -51,10 +51,19 @@ func (n *Notifier) Send(e *log.Entry) { format = "%s [%s]" 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) 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) lvl := e.Level.String() switch e.Level { diff --git a/notify/xmpp/internal.go b/notify/xmpp/internal.go index aaab0ed..6966adc 100644 --- a/notify/xmpp/internal.go +++ b/notify/xmpp/internal.go @@ -7,5 +7,15 @@ import ( ) func formatEntry(e *log.Entry) string { - return fmt.Sprintf("[%s] [%s] %s", e.Hostname, e.Level, e.Text) + 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) + + } 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) }