Go logging


The Go Programming Language or golang can log to Papertrail via 3 methods.


Method A: Transmit from Go app

Have the Go app transmit logs to Papertrail with the standard syslog package or a fork like srslog.

Call syslog.Dial with the hostname and port provided by Papertrail. For example:

import "log/syslog"

w, err := syslog.Dial("udp", "logsN.papertrailapp.com:XXXXX", LOG_EMERG | LOG_KERN, "myapp")
if err != nil {
    log.Fatal("failed to dial syslog")
w.Info("Any log message")
w.Err("Another log message")

Method B: Via a text log file

Log to a text log file(s), then transmit the log files to Papertrail. This does not require any modifications to the Go app.

Method C: Via local syslog daemon

Use the Go syslog package to send logs to a local syslog daemon (example). Have the local syslog daemon transmit the logs to Papertrail using Papertrail’s Unix/Linux syslog instructions.