From 5f74be54e6ca62df8022754d4716581d53392de2 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Sat, 24 Jun 2017 11:52:12 +0200 Subject: [PATCH] [TASK] start of notify --- cmd/logmania/selflog.go | 5 ++++- notify/main.go | 3 --- notify/xmpp/internal.go | 2 +- notify/xmpp/main.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/logmania/selflog.go b/cmd/logmania/selflog.go index 8a35ca9..4e576cc 100644 --- a/cmd/logmania/selflog.go +++ b/cmd/logmania/selflog.go @@ -32,7 +32,10 @@ func (l *SelfLogger) Hook(e *log.Entry) { l.lastMsg = e.Text l.lastTime = 1 } - database.InsertEntry("", e) + dbEntry := database.InsertEntry("", e) + if dbEntry != nil && notifier != nil { + notifier.Send(dbEntry) + } } func (l *SelfLogger) Close() { diff --git a/notify/main.go b/notify/main.go index 10af8b0..fcb158b 100644 --- a/notify/main.go +++ b/notify/main.go @@ -17,6 +17,3 @@ type NotifyInit func(*lib.NotifyConfig) Notifier func AddNotifier(n NotifyInit) { NotifyRegister = append(NotifyRegister, n) } - -func Start(config *lib.NotifyConfig) { -} diff --git a/notify/xmpp/internal.go b/notify/xmpp/internal.go index d17321e..f108ef7 100644 --- a/notify/xmpp/internal.go +++ b/notify/xmpp/internal.go @@ -2,6 +2,6 @@ package xmpp import "github.com/genofire/logmania/database" -func FormatEntry(e *database.Entry) string { +func formatEntry(e *database.Entry) string { return e.Text } diff --git a/notify/xmpp/main.go b/notify/xmpp/main.go index be90700..c882db9 100644 --- a/notify/xmpp/main.go +++ b/notify/xmpp/main.go @@ -34,8 +34,8 @@ func NotifyInit(config *lib.NotifyConfig) notify.Notifier { func (n *Notifier) Send(e *database.Entry) { users := database.UserByApplication(e.ApplicationID) for _, user := range users { - if user.NotifyXMPP && user.NotifyAfterLoglevel <= log.LogLevel(e.Level) { - n.client.SendHtml(xmpp.Chat{Remote: user.XMPP, Type: "chat", Text: FormatEntry(e)}) + if user.NotifyXMPP && log.LogLevel(e.Level) >= user.NotifyAfterLoglevel { + n.client.SendHtml(xmpp.Chat{Remote: user.XMPP, Type: "chat", Text: formatEntry(e)}) } } }