Skip to content

jjcollinge/logrus-appinsights

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status codecov

Application Insights Hook for Logrus :walrus:

Usage

See examples folder.

package main

import (
	"time"

	"github.com/jjcollinge/logrus-appinsights"
	log "github.com/sirupsen/logrus"
)

func init() {
	hook, err := logrus_appinsights.New("my_client", logrus_appinsights.Config{
		InstrumentationKey: "instrumentation_key",
		MaxBatchSize:       10,              // optional
		MaxBatchInterval:   time.Second * 5, // optional
	})
	if err != nil || hook == nil {
		panic(err)
	}

	// set custom levels
	hook.SetLevels([]log.Level{
		log.PanicLevel,
		log.ErrorLevel,
	})

	// ignore fields
	hook.AddIgnore("private")
	log.AddHook(hook)
}

func main() {

	f := log.Fields{
		"field1":  "field1_value",
		"field2":  "field2_value",
		"private": "private_value",
	}

	// Send log to Application Insights
	for {
		log.WithFields(f).Error("my message")
		time.Sleep(time.Second * 1)
	}
}

About

Application Insights Hook for Logrus logging framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages