sumologrus

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 12 Imported by: 0

README

sumologrus

deepcode codecov mmarinm

SumoLogic Hook for Logrus

Description

Sumologic hook for logrus helps upload logs to Sumologic HTTP Source asynchronously. Logs are flushed to Sumologic periodically (5 sec), when size of the batch reaches 250 logs or by explicitly calling Flush method. For real time logs set batch size to 1

Configuration

The following tables list the configurable parameters

Parameter Description Default
EndpointURL Sumologic endpoint ""
Tags Sumologic tags []
Host Sumologic host ""
Level Log Level logrus.PanicLevel
Interval Time interval to flush logs 5s
BatchSize Limits number of batched logs 250
GZip Compresses the payload before uploading false
Verbose Enables Sumorus hook logs false

Usage

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/mmarinm/sumologrus"
)

var endpoint string = "YOUR_SUMOLOGIC_HTTP_HOSTED_ENDPOINT"
var host = "YOUR_HOST_NAME"

func main() {
	log := logrus.New()
	sumoLogicHook := sumologrus.New(endpoint, host, logrus.InfoLevel, "tag1", "tag2")
	defer sumoLogicHook.Flush()
	log.Hooks.Add(sumoLogicHook)

	log.WithFields(logrus.Fields{
		"name": "hurley",
		"age":  29,
	}).Error("Hello world!")
}
Override default Config values:
package main

import (
	"github.com/sirupsen/logrus"
	"github.com/mmarinm/sumologrus"
	"time"
)

var endpoint string = "YOUR_SUMOLOGIC_HTTP_HOSTED_ENDPOINT"
var host = "YOUR_HOST_NAME"

func main() {
	log := logrus.New()
	sumoLogicHook, err := sumologrus.NewWithConfig(sumologrus.Config{
		EndPointURL: endpoint, 
		Tags:        []string{"tag1", "tag2"},
		Host:        host, 
		Level:       logrus.InfoLevel, 
		Interval:    3 * time.Second,
		BatchSize:   10,
		GZip:        true,
		Verbose:     true,
	})
	if err != nil {
		panic(err)
	}
	
	defer sumoLogicHook.Flush()
	log.Hooks.Add(sumoLogicHook)

	log.WithFields(logrus.Fields{
		"name": "sawyer",
		"age":  29,
	}).Error("Hello world!")
}

Documentation

Index

Constants

View Source
const DefaultBatchSize = 250
View Source
const DefaultInterval = 5 * time.Second

Variables

View Source
var (
	// This error is returned by methods of the `Client` interface when they are
	// called after the client was already closed.
	ErrClosed = errors.New("the client was already closed")

	// This error is used to notify the application that too many requests are
	// already being sent and no more messages can be accepted.
	ErrTooManyRequests = errors.New("too many requests are already in-flight")
)

Functions

This section is empty.

Types

type Config added in v1.0.1

type Config struct {
	EndPointURL string
	Tags        []string
	Host        string
	Level       logrus.Level
	Interval    time.Duration
	BatchSize   int
	Verbose     bool
	GZip        bool

	// The retry policy used by the client to resend requests that have failed.
	// The function is called with how many times the operation has been retried
	// and is expected to return how long the client should wait before trying
	// again.
	// If not set the client will fallback to use a default retry policy.
	RetryAfter func(int) time.Duration
	// contains filtered or unexported fields
}

type ConfigError added in v1.0.1

type ConfigError struct {
	Reason string
	Field  string

	// The value of the configuration field that caused the error.
	Value interface{}
}

ConfigError is returned by the `NewWithConfig` function when the one of the configuration fields was set to an impossible value (like a negative duration).

func (ConfigError) Error added in v1.0.1

func (e ConfigError) Error() string

type SumoLogicHook

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

func New added in v1.0.1

func New(endPointUrl string, host string, level logrus.Level, tags ...string) *SumoLogicHook

func NewWithConfig added in v1.0.1

func NewWithConfig(c Config) (*SumoLogicHook, error)

func (*SumoLogicHook) Fire

func (h *SumoLogicHook) Fire(entry *logrus.Entry) (err error)

func (*SumoLogicHook) Flush

func (h *SumoLogicHook) Flush() (err error)

func (*SumoLogicHook) Levels

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

type SumoLogicMesssage

type SumoLogicMesssage struct {
	Tags  []string    `json:"tags"`
	Host  string      `json:"host"`
	Level string      `json:"level"`
	Data  interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

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