change logging lib

This commit is contained in:
Martin/Geno 2019-06-20 09:25:43 +02:00
parent a5b0b06b3b
commit 840142fc1d
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
17 changed files with 33 additions and 32 deletions

View File

@ -3,7 +3,8 @@ package bot
import ( import (
"fmt" "fmt"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
logstd "github.com/bdlm/std/logger"
"dev.sum7.eu/genofire/logmania/database" "dev.sum7.eu/genofire/logmania/database"
) )
@ -21,7 +22,7 @@ func NewPriority(db *database.DB) *Command {
return "invalid: [channel] Priority" return "invalid: [channel] Priority"
} }
to := from to := from
var max log.Level var max logstd.Level
var err error var err error
if len(params) > 1 { if len(params) > 1 {
@ -40,7 +41,7 @@ func NewPriority(db *database.DB) *Command {
n.MaxPrioIn = max n.MaxPrioIn = max
return fmt.Sprintf("set filter for %s to %s", to, max.String()) return fmt.Sprintf("set filter for %s to %s", to, max)
}, },
}, },
{ {
@ -49,7 +50,7 @@ func NewPriority(db *database.DB) *Command {
Action: func(from string, params []string) string { Action: func(from string, params []string) string {
msg := "priority: \n" msg := "priority: \n"
for _, n := range db.Notifies { for _, n := range db.Notifies {
msg = fmt.Sprintf("%s%s - %s\n", msg, n.Address(), n.MaxPrioIn.String()) msg = fmt.Sprintf("%s%s - %s\n", msg, n.Address(), n.MaxPrioIn)
} }
return msg return msg
}, },
@ -64,7 +65,7 @@ func NewPriority(db *database.DB) *Command {
of := params[0] of := params[0]
msg := "priority: \n" msg := "priority: \n"
if notify, ok := db.NotifiesByAddress[of]; ok { if notify, ok := db.NotifiesByAddress[of]; ok {
msg = fmt.Sprintf("%s %s is %s", msg, of, notify.MaxPrioIn.String()) msg = fmt.Sprintf("%s %s is %s", msg, of, notify.MaxPrioIn)
} }
return msg return msg
}, },
@ -73,7 +74,7 @@ func NewPriority(db *database.DB) *Command {
Action: func(from string, params []string) string { Action: func(from string, params []string) string {
msg := "priority: \n" msg := "priority: \n"
if notify, ok := db.NotifiesByAddress[from]; ok { if notify, ok := db.NotifiesByAddress[from]; ok {
msg = fmt.Sprintf("%s %s is %s", msg, from, notify.MaxPrioIn.String()) msg = fmt.Sprintf("%s %s is %s", msg, from, notify.MaxPrioIn)
} }
return msg return msg
}, },

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -6,7 +6,7 @@ import (
"syscall" "syscall"
"time" "time"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"dev.sum7.eu/genofire/golang-lib/file" "dev.sum7.eu/genofire/golang-lib/file"

View File

@ -4,7 +4,8 @@ import (
"regexp" "regexp"
"time" "time"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
logstd "github.com/bdlm/std/logger"
) )
const AlertMsg = "alert service from logmania, device did not send new message for a while" const AlertMsg = "alert service from logmania, device did not send new message for a while"
@ -13,7 +14,7 @@ type DB struct {
// depraced Format -> transformation to new format by db.update() // depraced Format -> transformation to new format by db.update()
Hostname map[string]string `json:"hostname,omitempty"` Hostname map[string]string `json:"hostname,omitempty"`
HostTo map[string]map[string]bool `json:"host_to,omitempty"` HostTo map[string]map[string]bool `json:"host_to,omitempty"`
MaxPrioIn map[string]log.Level `json:"maxLevel,omitempty"` MaxPrioIn map[string]logstd.Level `json:"maxLevel,omitempty"`
RegexIn map[string]map[string]*regexp.Regexp `json:"regexIn,omitempty"` RegexIn map[string]map[string]*regexp.Regexp `json:"regexIn,omitempty"`
Lastseen map[string]time.Time `json:"lastseen,omitempty"` Lastseen map[string]time.Time `json:"lastseen,omitempty"`
LastseenNotify map[string]time.Time `json:"-"` LastseenNotify map[string]time.Time `json:"-"`

View File

@ -4,7 +4,8 @@ import (
"regexp" "regexp"
"strings" "strings"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
logstd "github.com/bdlm/std/logger"
) )
type Notify struct { type Notify struct {
@ -12,7 +13,7 @@ type Notify struct {
To string `json:"to"` To string `json:"to"`
RegexIn map[string]*regexp.Regexp `json:"regexIn"` RegexIn map[string]*regexp.Regexp `json:"regexIn"`
RegexReplace map[string]string `json:"regexReplace"` RegexReplace map[string]string `json:"regexReplace"`
MaxPrioIn log.Level `json:"maxLevel"` MaxPrioIn logstd.Level `json:"maxLevel"`
regexReplaceExpression map[string]*regexp.Regexp regexReplaceExpression map[string]*regexp.Regexp
} }

View File

@ -2,7 +2,7 @@ package database
import ( import (
"dev.sum7.eu/genofire/golang-lib/file" "dev.sum7.eu/genofire/golang-lib/file"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
) )
func ReadDBFile(path string) *DB { func ReadDBFile(path string) *DB {

View File

@ -1,7 +1,7 @@
package all package all
import ( import (
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
"dev.sum7.eu/genofire/logmania/input" "dev.sum7.eu/genofire/logmania/input"
) )

View File

@ -4,7 +4,8 @@ import (
"encoding/json" "encoding/json"
"strconv" "strconv"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
logstd "github.com/bdlm/std/logger"
) )
type JournalMessage struct { type JournalMessage struct {
@ -34,7 +35,7 @@ type JournalMessage struct {
Message string `json:"MESSAGE"` Message string `json:"MESSAGE"`
} }
var PriorityMap = map[int]log.Level{ var PriorityMap = map[int]logstd.Level{
0: log.PanicLevel, // emerg 0: log.PanicLevel, // emerg
1: log.PanicLevel, // alert 1: log.PanicLevel, // alert
2: log.PanicLevel, // crit 2: log.PanicLevel, // crit

View File

@ -3,8 +3,8 @@ package journald_json
import ( import (
"net" "net"
"github.com/bdlm/log"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
log "github.com/sirupsen/logrus"
"dev.sum7.eu/genofire/logmania/input" "dev.sum7.eu/genofire/logmania/input"
) )

View File

@ -1,7 +1,7 @@
package input package input
import ( import (
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
) )
var Register = make(map[string]Init) var Register = make(map[string]Init)

View File

@ -1,12 +1,13 @@
package syslog package syslog
import ( import (
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
logstd "github.com/bdlm/std/logger"
libSyslog "dev.sum7.eu/genofire/logmania/lib/syslog" libSyslog "dev.sum7.eu/genofire/logmania/lib/syslog"
) )
var SyslogPriorityMap = map[int]log.Level{ var SyslogPriorityMap = map[int]logstd.Level{
0: log.PanicLevel, 0: log.PanicLevel,
1: log.PanicLevel, 1: log.PanicLevel,
2: log.PanicLevel, 2: log.PanicLevel,

View File

@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
) )
func TestToEntry(t *testing.T) { func TestToEntry(t *testing.T) {

View File

@ -3,8 +3,8 @@ package syslog
import ( import (
"net" "net"
"github.com/bdlm/log"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
log "github.com/sirupsen/logrus"
"dev.sum7.eu/genofire/logmania/input" "dev.sum7.eu/genofire/logmania/input"
) )

View File

@ -1,7 +1,7 @@
package all package all
import ( import (
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
"dev.sum7.eu/genofire/logmania/bot" "dev.sum7.eu/genofire/logmania/bot"
"dev.sum7.eu/genofire/logmania/database" "dev.sum7.eu/genofire/logmania/database"
@ -62,7 +62,7 @@ func (out *Output) sender() {
} }
} }
if !send { if !send {
logger.Warnf("notify not send to %s: [%s] %s", to.Address(), c.Level.String(), c.Message) logger.Warnf("notify not send to %s: [%s] %s", to.Address(), c.Level, c.Message)
} }
} }
} }

View File

@ -5,8 +5,8 @@ import (
"path" "path"
"regexp" "regexp"
"github.com/bdlm/log"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
log "github.com/sirupsen/logrus"
"dev.sum7.eu/genofire/logmania/bot" "dev.sum7.eu/genofire/logmania/bot"
"dev.sum7.eu/genofire/logmania/database" "dev.sum7.eu/genofire/logmania/database"

View File

@ -1,7 +1,7 @@
package output package output
import ( import (
log "github.com/sirupsen/logrus" "github.com/bdlm/log"
"dev.sum7.eu/genofire/logmania/bot" "dev.sum7.eu/genofire/logmania/bot"
"dev.sum7.eu/genofire/logmania/database" "dev.sum7.eu/genofire/logmania/database"

View File

@ -8,8 +8,8 @@ import (
xmpp "dev.sum7.eu/genofire/yaja/xmpp" xmpp "dev.sum7.eu/genofire/yaja/xmpp"
"dev.sum7.eu/genofire/yaja/xmpp/base" "dev.sum7.eu/genofire/yaja/xmpp/base"
"dev.sum7.eu/genofire/yaja/xmpp/x/muc" "dev.sum7.eu/genofire/yaja/xmpp/x/muc"
"github.com/bdlm/log"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
log "github.com/sirupsen/logrus"
"dev.sum7.eu/genofire/logmania/bot" "dev.sum7.eu/genofire/logmania/bot"
"dev.sum7.eu/genofire/logmania/database" "dev.sum7.eu/genofire/logmania/database"
@ -49,11 +49,7 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
channels := make(map[string]bool) channels := make(map[string]bool)
jid := xmppbase.NewJID(config.JID) jid := xmppbase.NewJID(config.JID)
client := &xmpp_client.Client{ client, err := xmpp_client.NewClient(jid, config.Password)
JID: jid,
Logging: logger.WithField("jid", jid.String()),
}
err := client.Connect(config.Password)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)