logruzio

package module
v0.0.0-...-cd769a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2018 License: MIT Imports: 6 Imported by: 0

README

Logzio hook for Logrus

Send Logrus logs to Logzio

Getting Started

Get Logzio token
  1. Go to Logzio website
  2. Sign in with your Logzio account
  3. Click the top menu gear icon (Account)
  4. The Logzio token is given in the account page
Initialize Logzio hook
package yourpackagename

import (
        "github.com/sirupsen/logrus"
        "github.com/bshuster-repo/logruzio"
)

const LOGZIO_TOKEN = "fjdhslGJHSDHG23edg"

func main() {
        ctx := logrus.Fields{
                "ID": "12adebacd8",
                "Version": "1.0.0-dev",
        }
        hook, err := logruzio.New(LOGZIO_TOKEN, "YourAppName", ctx)
        if err != nil {
                logrus.Fatal(err)
        }
        logrus.AddHook(hook)
        logrus.Info("Lets go!")
}

NOTE: Set LOGZIO_TOKEN to the Logzio token as mentioned in Get Logzio token.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook represents a Logrus Logzio hook

func New

func New(token string, appName string, ctx logrus.Fields) (*Hook, error)

New creates a default Logzio hook. What it does is taking `token` and `appName` and attaching them to the log data. In addition, it sets a connection to the Logzio's Logstash endpoint. If the connection fails, it returns an error.

To set more advanced configurations, initialize the hook in the following way:

hook := &Hook{HookOpts{
		Conn: myConn,
		Context: logrus.Fields{...},
		Formatter: myFormatter{}
}

func (*Hook) Fire

func (h *Hook) Fire(entry *logrus.Entry) error

Fire writes `entry` to Logzio

func (*Hook) Levels

func (h *Hook) Levels() []logrus.Level

Levels returns logging levels

func (*Hook) RetryConn

func (h *Hook) RetryConn()

RetryConn attempts to recreate Hook's connection

type HookOpts

type HookOpts struct {
	Conn      io.Writer
	Context   logrus.Fields
	Formatter logrus.Formatter
}

HookOpts represents Logrus Logzio hook options

type SimpleFormatter

type SimpleFormatter struct {
	// contains filtered or unexported fields
}

SimpleFormatter represents a simple JSON formatter

func (*SimpleFormatter) Format

func (f *SimpleFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats the log entry to a JSON format Logstash understands

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL