logrus

Hooks for logrus logging

Hooks for logrus

Example

package main

import (
  "github.com/onrik/logrus/filename"
  "github.com/onrik/logrus/sentry"
  log "github.com/Sirupsen/logrus"
)

var (
  dsn := "http://60a0257d7b5a429a8838e5f2ba873ec9:[email protected]/1"
)

func main() {
  filenameHook := filename.NewHook()
  filenameHook.SourceField = "custom_source_field" // Customize source field name
  log.AddHook(filenameHook)
  
  sentryHook := sentry.NewHook(dsn, log.PanicLevel, log.FatalLevel, log.ErrorLevel)
  log.AddHook(sentryHook)
  
  request, err := http.NewRequest("GET", "http://example.com", nil)
  log.WithFields(log.Fields{
    "error": err,
    "sentry": sentry.NewSentry(
      sentry.WithHttpRequest(request),
      sentry.WithUser("22", "testuser", "[email protected]", "127.0.0.1"),
    ),
  }).Info("Request info")
}

Related Repositories

logrus

logrus

Structured, pluggable logging for Go. ...

logrus

logrus

Obsolete, Please refer to gogap/logrus_mate ...

slackrus

slackrus

Slack hook for Logrus ...

negroni-logrus

negroni-logrus

logrus middleware for negroni ...

lfshook

lfshook

A local file system hook for golang logrus logger ...