logzruz

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2017 License: MIT Imports: 10 Imported by: 0

README

logzruz

GoDoc

Logrus hook for sending logs to logz.io.

Package logzruz provides a logrus hook for sending log messages to logz.io servers for further processing.

The library buffers messages until a user-defined threshold has been reached or a ticker triggers a regular buffer flush. By employing two methods of buffer flushing as well as providing a manual way to send messages, applications can utilise faster logging while making sure messages get sent within a reasonable time frame.

As of now, logzruz will send all message levels to logz.io

Installation

go get -u github.com/MorpheusXAUT/logzruz

Usage

logzruz can be added to logrus just like every other hook. Applications are only required to provide an API token for the hook to function:

package main

import (
    "github.com/Sirupsen/logrus"
	"github.com/MorpheusXAUT/logzruz"
)

func main() {
	logz, err := logzruz.NewHook(logzruz.HookOptions{
	    Token: "YOURLOGZIOTOKEN",
	}
	// check for token or URL parsing error
	if err != nil {
	    panic(err)
	}

	log.Hooks.Add(logz)

	log.Info("Hello to logz.io!")
}

Documentation

see https://godoc.org/github.com/MorpheusXAUT/logzruz

Attribution

logrus

Structured, pluggable logging library developed by Sirupsen.

License

MIT License

Documentation

Overview

Package logzruz provides a logrus hook for sending log messages to logz.io servers for further processing.

The library buffers messages until a user-defined threshold has been reached or a ticker triggers a regular buffer flush. By employing two methods of buffer flushing as well as providing a manual way to send messages, applications can utilise faster logging while making sure messages get sent within a reasonable time frame.

As of now, logzruz will send all message levels to logz.io

Index

Constants

View Source
const (
	// Version of the logzruz library
	Version = "1.0.0"
	// DefaultBufferCount defines the default number of messages to buffer before flushing logs
	DefaultBufferCount = 10
	// DefaultBufferInterval defines the default interval to check for messages to flush if not explicitly specified
	DefaultBufferInterval = time.Second * 10
	// DefaultForceFlushField to use for triggering a buffer flush forcefully if not explicitly specified
	DefaultForceFlushField = "logzruzForceFlush"
	// DefaultUserAgent to use for HTTP requests if not explicitly specified
	DefaultUserAgent = "logzruz v" + Version + " - github.com/MorpheusXAUT/logzruz"
	// LogzioDefaultURL specifies the default URL of the logz.io service to use
	LogzioDefaultURL = "https://listener.logz.io:8071/"
)

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 hook for shipping logs to logz.io services. Messages are buffered until a user-defined limit has been reached or sent on a regular interval.

func NewHook

func NewHook(options HookOptions) (*Hook, error)

NewHook creates a new logzruz hook using the provided options

func (*Hook) Fire

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

Fire is triggered by logrus on every message passed to the hook. The log entry is processed, additional context and data added as required and the JSON encoded payload is added to the message buffer. If the buffer count is reached or a flush is force via log-field or level, the bulk posting is initiated.

func (*Hook) Flush

func (hook *Hook) Flush() error

Flush allows applications to force a buffer flash, sending all stored messages to logz.io

func (*Hook) Levels

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

Levels returns the levels this hook is triggered on. As of now, logzruz will log every message to logz.io servers.

func (*Hook) Shutdown

func (hook *Hook) Shutdown() error

Shutdown cleanly shuts the hook buffer loop down and flushes all remaining messages

type HookOptions

type HookOptions struct {
	// App "name" to specify as a type for logz.io requests
	App string
	// BufferCount specifies the number of messages to buffer before flushing it (if not triggered by timed triggers before). Setting this value to -1 will disable buffering and instantly send messages (default 10)
	BufferCount int
	// BufferInterval specifies the duration to wait between each check for new buffered messages to send (default 10s)
	BufferInterval time.Duration
	// Client specifies the HTTP client to use for sending logs to the HTTPS log servers
	Client *http.Client
	// Context will be added to every log message
	Context logrus.Fields
	// ForceFlushField specifies the name of the log field triggering a force flush if present (default "logzruzForceFlush")
	ForceFlushField string
	// ForceFlushLevel allows for log messages higher than the level specified to be flushed instantly (default "fatal")
	ForceFlushLevel logrus.Level
	// Token stores the API token to authenticate to logz.io with
	Token string
	// URL allows users to overwrite the logz.io URL to send logs to. Should include protocol and port (default "https://listener.logz.io:8071/")
	URL string
	// UserAgent allows users to overwrite the default HTTP user-agent set for every request (default "logzruz vX.Y.Z - github.com/MorpheusXAUT/logzruz")
	UserAgent string
}

HookOptions contains all options and settings required to configure the hook. Applications only need to provide a Token, although the other options can be used to further modify the library's behaviour. If not provided, some options will be configured using defaults.

Jump to

Keyboard shortcuts

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