switch to syslog log
This commit is contained in:
parent
0ac8fcb908
commit
ae15e1341e
|
@ -2,10 +2,10 @@ package circleci
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
libHTTP "github.com/genofire/golang-lib/http"
|
||||
"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.Error(r.Body)
|
||||
log.Fatal("no readable payload")
|
||||
http.Error(w, fmt.Sprintf("no readable payload"), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
hook, ok := h.hooks[vcsURL]
|
||||
if !ok {
|
||||
log.Errorf("No hook found for: '%s'", vcsURL)
|
||||
log.Fatalf("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.New().AddField("type", "circleci").Info(msg)
|
||||
log.Printf("circle ci: %s", msg)
|
||||
ownXMPP.Notify(h.client, hook, msg)
|
||||
}
|
||||
|
|
|
@ -2,19 +2,18 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"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"
|
||||
configuration "github.com/genofire/hook2xmpp/config"
|
||||
"github.com/genofire/hook2xmpp/git"
|
||||
"github.com/genofire/hook2xmpp/syslog"
|
||||
ownXMPP "github.com/genofire/hook2xmpp/xmpp"
|
||||
)
|
||||
|
||||
|
@ -25,8 +24,8 @@ func main() {
|
|||
|
||||
config := configuration.ReadConfigFile(configFile)
|
||||
|
||||
if config.Logmania.Enable {
|
||||
logmania.Init(config.Logmania.Address, config.Logmania.Token, log.LogLevel(config.Logmania.Level))
|
||||
if config.Syslog.Enable {
|
||||
syslog.Bind(config)
|
||||
}
|
||||
|
||||
// load config
|
||||
|
@ -45,7 +44,7 @@ func main() {
|
|||
log.Panic(err)
|
||||
}
|
||||
|
||||
log.Infof("Started hock2xmpp with %s", client.JID())
|
||||
log.Printf("Started hock2xmpp with %s", client.JID())
|
||||
|
||||
client.SendHtml(xmpp.Chat{Remote: config.XMPP.StartupNotify, Type: "chat", Text: "startup of hock2xmpp"})
|
||||
go ownXMPP.Start(client)
|
||||
|
@ -74,5 +73,5 @@ func main() {
|
|||
|
||||
srv.Close()
|
||||
|
||||
log.Info("received", sig)
|
||||
log.Print("received", sig)
|
||||
}
|
||||
|
|
|
@ -2,19 +2,17 @@ package config
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
|
||||
"github.com/genofire/logmania/log"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Logmania struct {
|
||||
Syslog struct {
|
||||
Enable bool `toml:"enable"`
|
||||
Type string `toml:"type"`
|
||||
Address string `toml:"address"`
|
||||
Token string `toml:"token"`
|
||||
Level int `toml:"level"`
|
||||
} `toml:"logmania"`
|
||||
} `toml:"syslog"`
|
||||
|
||||
WebserverBind string `toml:"webserver_bind"`
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
libHTTP "github.com/genofire/golang-lib/http"
|
||||
"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.Errorf("No hook found for: '%s'", url)
|
||||
log.Fatalf("No hook found for: '%s'", url)
|
||||
return
|
||||
}
|
||||
|
||||
log.New().AddField("type", "git").Info(msg)
|
||||
log.Printf("git: %s", msg)
|
||||
ownXMPP.Notify(h.client, hook, msg)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package syslog
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/syslog"
|
||||
|
||||
"github.com/genofire/hook2xmpp/config"
|
||||
)
|
||||
|
||||
func Bind(config *config.Config) {
|
||||
sysLog, err := syslog.Dial(config.Syslog.Type, config.Syslog.Address, syslog.LOG_WARNING|syslog.LOG_DAEMON, "hook2xmpp")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.SetOutput(sysLog)
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package xmpp
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/genofire/hook2xmpp/config"
|
||||
"github.com/genofire/logmania/log"
|
||||
|
||||
xmpp "github.com/mattn/go-xmpp"
|
||||
)
|
||||
|
@ -16,7 +17,7 @@ func Start(client *xmpp.Client) {
|
|||
switch v := m.(type) {
|
||||
case xmpp.Chat:
|
||||
if v.Type == "chat" {
|
||||
log.Infof("from %s: %s", v.Remote, v.Text)
|
||||
log.Printf("from %s: %s", v.Remote, v.Text)
|
||||
}
|
||||
if v.Type == "groupchat" {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue