logruzio

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

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

Go to latest
Published: Jan 29, 2022 License: MIT Imports: 4 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(host, token, appName string, fields 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{
		Sender: logzioSender,
		AdditionalFields: logrus.Fields{...},
}

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

type HookOpts

type HookOpts struct {
	Sender           *logzio.LogzioSender
	AdditionalFields logrus.Fields
}

HookOpts represents Logrus Logzio hook options

Jump to

Keyboard shortcuts

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