Papertrail provides hosted log management. Once stored in Papertrail, you can group your logs on various dimensions, search them, and trigger alerts.
In most deployments, you'll want to send logs to Papertrail via their remote_syslog daemon, which requires no application-specific configuration. This hook is intended for relatively low-volume logging, likely in managed cloud hosting deployments where installing remote_syslog
is not possible.
You can find your Papertrail port(Accepting TCP/TLS, UDP) on your Papertrail account page. Substitute it below for YOUR_PAPERTRAIL_PORT
.
For YOUR_APP_NAME
and YOUR_HOST_NAME
, substitute a short strings that will readily identify your application and server in the logs. If you leave YOUR_HOST_NAME
empty, papertrail will replace it with your ip.
import (
log "github.com/sirupsen/logrus"
"github.com/polds/logrus-papertrail-hook"
)
func main() {
hook, err := logrus_papertrail.NewPapertrailHook(&logrus_papertrail.Hook{
Host: "logs.papertrailapp.com",
Port: YOUR_PAPERTRAIL_PORT,
Hostname: YOUR_HOST_NAME,
Appname: YOUR_APP_NAME
})
hook.SetLevels([]log.Level{log.ErrorLevel, log.WarnLevel})
if err == nil {
log.AddHook(hook)
}
log.Warning("Here is you message")
}