logrus_appinsights

package module
v0.0.0-...-9b66602 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: MIT Imports: 5 Imported by: 8

README

Build Status Coverage Status codecov

Application Insights Hook for Logrus

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppInsightsHook

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

AppInsightsHook is a logrus hook for Application Insights

func New

func New(name string, conf Config) (*AppInsightsHook, error)

New returns an initialised logrus hook for Application Insights

func NewWithAppInsightsConfig

func NewWithAppInsightsConfig(name string, conf *appinsights.TelemetryConfiguration) (*AppInsightsHook, error)

NewWithAppInsightsConfig returns an initialised logrus hook for Application Insights

func (*AppInsightsHook) AddFilter

func (hook *AppInsightsHook) AddFilter(name string, fn func(interface{}) interface{})

AddFilter adds a custom filter function.

func (*AppInsightsHook) AddIgnore

func (hook *AppInsightsHook) AddIgnore(name string)

AddIgnore adds field name to ignore.

func (*AppInsightsHook) Fire

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

Fire is invoked by logrus and sends log data to Application Insights.

func (*AppInsightsHook) Levels

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

Levels returns logging level to fire this hook.

func (*AppInsightsHook) SetAsync

func (hook *AppInsightsHook) SetAsync(async bool)

SetAsync sets async flag for sending logs asynchronously. If use this true, Fire() does not return error.

func (*AppInsightsHook) SetLevels

func (hook *AppInsightsHook) SetLevels(levels []logrus.Level)

SetLevels sets logging level to fire this hook.

type Config

type Config struct {
	InstrumentationKey string
	EndpointUrl        string
	MaxBatchSize       int
	MaxBatchInterval   time.Duration
}

Config for Application Insights settings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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