No description or website provided.
Go
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore port from messaging Oct 19, 2016
README.md
glide.lock add glide files Oct 19, 2016
glide.yaml add glide files Oct 19, 2016
nats.go rename package to nhook Oct 25, 2016
nats_logrus_hook.go expose the Formatter in the hook Jan 20, 2017
nats_logrus_hook_test.go remove stupid extra err return Oct 25, 2016

README.md

A NATS hook for Logrus

This lib will let you use any nats connection to connect, but does provide some convience methods to help connection setup.

The helpers all assume you're using a TLS connection.

Examples:

setup and add hook to default logger. Connection is assumed TLS with no error handler.

  conf := &HookConf{
    Subject: "logs.group.hostname",
    Dimensions: map[string]interface{}{
      "hostname": "server-1",
    },
    NatsConfig: NatsConfig{
      CAFiles: []string{"ca.pem"},
      KeyFile: "key.pem",
      CertFile: "cert.pem",
      Servers: []string{"server-2", "server-3"},
    },
  }
  nc, hook, err := AddNatsHook(conf)

setup with an error handler and TLS

  natsConfig := &NatsConfig {
    CAFiles: []string{"ca.pem"},
    KeyFile: "key.pem",
    CertFile: "cert.pem",
    Servers: []string{"server-2", "server-3"},
  }
  e := func(nc *nats.Conn, sub *nats.Subject, err error) {
    logrus.WithError(err).Fatal("error!!!")
  }
  nc, err := ConnectToNatsWithError(natsConfig, e)

  hook, err := NewNatsHook(nc, "logs.group.host")
  logrus.AddHook(hook)

setup with your own connection

  nc, err := nats.Connect("server-2")
  hook, err := NewNatsHook(nc, "logs.group.host")
  logrus.AddHook(hook)

You can modify the formatter on the hook and the level that it is connected to as well. By default it will use the logrus's JSONFormatter.