Skip to content

mmarinm/sumologrus

Repository files navigation

sumologrus

deepcode codecov mmarinm

SumoLogic Hook for Logrus :walrus:

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!")
}