Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ type Flags struct {

YubiCloudID string
YubiCloudKey string

LogglyToken string
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ var (
// YubiCloud params
yubiCloudID = flag.String("yubicloud_id", "", "YubiCloud API id")
yubiCloudKey = flag.String("yubicloud_key", "", "YubiCloud API key")
// Loggly URL
logglyToken = flag.String("loggly_token", "", "Loggly token")
)

func main() {
Expand Down Expand Up @@ -95,6 +97,8 @@ func main() {

YubiCloudID: *yubiCloudID,
YubiCloudKey: *yubiCloudKey,

LogglyToken: *logglyToken,
}

// Generate a mux
Expand Down
24 changes: 24 additions & 0 deletions setup/loggly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package setup

import (
"github.com/Sirupsen/logrus"
"github.com/segmentio/go-loggly"
)

type logglyHook struct {
Loggly *loggly.Client
}

func (h *logglyHook) Fire(entry *logrus.Entry) error {
entry.Data["message"] = entry.Message
return h.Loggly.Send(map[string]interface{}(entry.Data))
}

func (h *logglyHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.WarnLevel,
logrus.ErrorLevel,
logrus.FatalLevel,
logrus.PanicLevel,
}
}
8 changes: 8 additions & 0 deletions setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/dancannon/gorethink"
"github.com/googollee/go-socket.io"
"github.com/rs/cors"
"github.com/segmentio/go-loggly"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
"gopkg.in/igm/sockjs-go.v2/sockjs"
Expand Down Expand Up @@ -47,6 +48,13 @@ func PrepareMux(flags *env.Flags) *web.Mux {
log.Formatter = &logrus.JSONFormatter{}
}

// Install logrus hooks
if flags.LogglyToken != "" {
log.Hooks.Add(&logglyHook{
Loggly: loggly.New(flags.LogglyToken),
})
}

// Pass it to the environment package
env.Log = log

Expand Down