[TASK] start of notify

This commit is contained in:
Martin Geno 2017-06-24 11:52:12 +02:00
parent f94f35c657
commit 5f74be54e6
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
4 changed files with 7 additions and 7 deletions

View File

@ -32,7 +32,10 @@ func (l *SelfLogger) Hook(e *log.Entry) {
l.lastMsg = e.Text l.lastMsg = e.Text
l.lastTime = 1 l.lastTime = 1
} }
database.InsertEntry("", e) dbEntry := database.InsertEntry("", e)
if dbEntry != nil && notifier != nil {
notifier.Send(dbEntry)
}
} }
func (l *SelfLogger) Close() { func (l *SelfLogger) Close() {

View File

@ -17,6 +17,3 @@ type NotifyInit func(*lib.NotifyConfig) Notifier
func AddNotifier(n NotifyInit) { func AddNotifier(n NotifyInit) {
NotifyRegister = append(NotifyRegister, n) NotifyRegister = append(NotifyRegister, n)
} }
func Start(config *lib.NotifyConfig) {
}

View File

@ -2,6 +2,6 @@ package xmpp
import "github.com/genofire/logmania/database" import "github.com/genofire/logmania/database"
func FormatEntry(e *database.Entry) string { func formatEntry(e *database.Entry) string {
return e.Text return e.Text
} }

View File

@ -34,8 +34,8 @@ func NotifyInit(config *lib.NotifyConfig) notify.Notifier {
func (n *Notifier) Send(e *database.Entry) { func (n *Notifier) Send(e *database.Entry) {
users := database.UserByApplication(e.ApplicationID) users := database.UserByApplication(e.ApplicationID)
for _, user := range users { for _, user := range users {
if user.NotifyXMPP && user.NotifyAfterLoglevel <= log.LogLevel(e.Level) { if user.NotifyXMPP && log.LogLevel(e.Level) >= user.NotifyAfterLoglevel {
n.client.SendHtml(xmpp.Chat{Remote: user.XMPP, Type: "chat", Text: FormatEntry(e)}) n.client.SendHtml(xmpp.Chat{Remote: user.XMPP, Type: "chat", Text: formatEntry(e)})
} }
} }
} }