apex / log

Structured logging package for Go.
MIT License
1.37k stars 112 forks source link

#81: syslog handler #84

Open nergdron opened 4 years ago

nergdron commented 4 years ago

This is my first pass at implementing this handler. I wrote a quick little test script which seems to produce the behaviour I expect, but I welcome feedback on it.

package main

import (
  "errors"
  stdlog "log"
  "github.com/apex/log"
  "github.com/apex/log/handlers/syslog"
)

func main() {
  h, err := syslog.New("", 0, "test")
  if err != nil {
    stdlog.Fatal(err)
  }
  log.SetHandler(h)
  log.WithError(errors.New("errormsg")).WithFields(log.Fields{
        "app": "myapp",
        "env": "prod",
    }).Warn("something went wrong\nunfortunately")
}
nergdron commented 4 years ago

@tj: ok, I think that works alright, how's this look to you?