[TASK] use logmania logging

This commit is contained in:
Martin Geno 2017-06-16 14:55:07 +02:00
parent ff20d7e388
commit 0ac8fcb908
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
5 changed files with 31 additions and 17 deletions

View File

@ -5,7 +5,7 @@ import (
"net/http"
libHTTP "github.com/genofire/golang-lib/http"
"github.com/genofire/golang-lib/log"
"github.com/genofire/logmania/log"
xmpp "github.com/mattn/go-xmpp"
"github.com/genofire/hook2xmpp/config"
@ -37,14 +37,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
payload := body["payload"].(map[string]interface{})
vcsURL, ok := payload["vcs_url"].(string)
if !ok {
log.Log.Error(r.Body)
log.Error(r.Body)
http.Error(w, fmt.Sprintf("no readable payload"), http.StatusInternalServerError)
return
}
hook, ok := h.hooks[vcsURL]
if !ok {
log.Log.Errorf("No hook found for: '%s'", vcsURL)
log.Errorf("No hook found for: '%s'", vcsURL)
http.Error(w, fmt.Sprintf("no configuration for circleci for url %s", vcsURL), http.StatusNotFound)
return
}
@ -55,6 +55,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
subject := payload["subject"].(string)
msg := fmt.Sprintf("[%s] %s (%0.fs) - #%0.f: %s \n%s", vcsURL, status, buildTime/1000, buildNum, subject, buildURL)
log.Log.WithField("type", "circleci").Print(msg)
log.New().AddField("type", "circleci").Info(msg)
ownXMPP.Notify(h.client, hook, msg)
}

View File

@ -7,7 +7,9 @@ import (
"os/signal"
"syscall"
"github.com/genofire/golang-lib/log"
"github.com/genofire/logmania/log"
logmania "github.com/genofire/logmania/log/hook/client"
_ "github.com/genofire/logmania/log/hook/output"
"github.com/mattn/go-xmpp"
"github.com/genofire/hook2xmpp/circleci"
@ -21,8 +23,13 @@ func main() {
flag.StringVar(&configFile, "config", configFile, "path of configuration file")
flag.Parse()
// load config
config := configuration.ReadConfigFile(configFile)
if config.Logmania.Enable {
logmania.Init(config.Logmania.Address, config.Logmania.Token, log.LogLevel(config.Logmania.Level))
}
// load config
options := xmpp.Options{
Host: config.XMPP.Host,
User: config.XMPP.Username,
@ -35,10 +42,10 @@ func main() {
}
client, err := options.NewClient()
if err != nil {
log.Log.Panic(err)
log.Panic(err)
}
log.Log.Infof("Started hock2xmpp with %s", client.JID())
log.Infof("Started hock2xmpp with %s", client.JID())
client.SendHtml(xmpp.Chat{Remote: config.XMPP.StartupNotify, Type: "chat", Text: "startup of hock2xmpp"})
go ownXMPP.Start(client)
@ -67,5 +74,5 @@ func main() {
srv.Close()
log.Log.Info("received", sig)
log.Info("received", sig)
}

View File

@ -5,10 +5,17 @@ import (
"github.com/BurntSushi/toml"
"github.com/genofire/golang-lib/log"
"github.com/genofire/logmania/log"
)
type Config struct {
Logmania struct {
Enable bool `toml:"enable"`
Address string `toml:"address"`
Token string `toml:"token"`
Level int `toml:"level"`
} `toml:"logmania"`
WebserverBind string `toml:"webserver_bind"`
XMPP struct {
@ -37,10 +44,10 @@ func ReadConfigFile(path string) *Config {
config := &Config{}
file, err := ioutil.ReadFile(path)
if err != nil {
log.Log.Panic(err)
log.Panic(err)
}
if err := toml.Unmarshal(file, config); err != nil {
log.Log.Panic(err)
log.Panic(err)
}
return config

View File

@ -4,7 +4,7 @@ import (
"net/http"
libHTTP "github.com/genofire/golang-lib/http"
"github.com/genofire/golang-lib/log"
"github.com/genofire/logmania/log"
xmpp "github.com/mattn/go-xmpp"
"github.com/genofire/hook2xmpp/config"
@ -54,10 +54,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hook, ok := h.hooks[url]
if !ok {
log.Log.Errorf("No hook found for: '%s'", url)
log.Errorf("No hook found for: '%s'", url)
return
}
log.Log.WithField("type", "git").Print(msg)
log.New().AddField("type", "git").Info(msg)
ownXMPP.Notify(h.client, hook, msg)
}

View File

@ -1,8 +1,8 @@
package xmpp
import (
"github.com/genofire/golang-lib/log"
"github.com/genofire/hook2xmpp/config"
"github.com/genofire/logmania/log"
xmpp "github.com/mattn/go-xmpp"
)
@ -16,7 +16,7 @@ func Start(client *xmpp.Client) {
switch v := m.(type) {
case xmpp.Chat:
if v.Type == "chat" {
log.Log.Infof("from %s: %s", v.Remote, v.Text)
log.Infof("from %s: %s", v.Remote, v.Text)
}
if v.Type == "groupchat" {
}