sumologrus

package module
v0.0.0-...-1e239a4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 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 in real time by explicitly calling Flush method.

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
MaxConcurrentRequests max concurrent requests 1000
GZip Compresses the payload before uploading false
Verbose Enables Sumorus hook logs false

Usage

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/eitan-kr/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/eitan-kr/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, 
		MaxConcurrentRequests:   1000,
		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

This section is empty.

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

type Config struct {
	EndPointURL string
	Tags        []string
	Host        string
	Level       logrus.Level
	Verbose     bool
	GZip        bool

	// The maximum number of goroutines that will be spawned by a client to send
	// requests to the backend API.
	// This field is not exported and only exposed internally to let unit tests
	// mock the current time.
	MaxConcurrentRequests int

	// 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
}

type ConfigError

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

func (e ConfigError) Error() string

type SumoLogicHook

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

func New

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

func NewWithConfig

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 {
	Host    string                 `json:"host,omitempty"`
	Tags    []string               `json:"tags,omitempty"`
	Level   string                 `json:"level,omitempty"`
	Fields  map[string]interface{} `json:"fields,omitempty"`
	Message string                 `json:"message,omitempty"`
}

Jump to

Keyboard shortcuts

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