Giter Club home page Giter Club logo

logrus-opsgenie-hook's Introduction

OpsGenie Hook for Logrus :walrus: Build Status godoc reference

This hook is used to send your errors to OpsGenie as an alert. It uses the opsgenie-go-sdk to handle the requests. The levels that are blocked by this hook are log.Error, log.Fatal, and log.Panic.

Usage

The only configuration needed for this hook is the OpsGenie API key you wish to use. However the alert struct must be created yourself with the fields you wish to use and added as a logrus.Entry using WithField("request", alert).

The message of the alert will default to the log level message: Error("some error"), although if WithError(err) is used that will become a priority.

import (
    "fmt"

    "github.com/jackfazackerley/logrus-opsgenie-hook"
    "github.com/opsgenie/opsgenie-go-sdk/alertsv2"
    "github.com/sirupsen/logrus"
)

func main() {
    log := logrus.New()

    hook, err := opsgenie.NewHook("some API key")
    if err != nil {
        panic(err)
    }

    log.AddHook(hook)

    alert := alertsv2.CreateAlertRequest{
        Alias: "some alias here",
        Description: "some description here",
        Teams: []alertsv2.TeamRecipient{
            &alertsv2.Team{
                Name: "Dev",
            },
        },
        Source:   "some source here",
        Priority: alertsv2.P5,
    }

    // Uses default message as the alert message
    log.WithField("alert", alert).Error("default message value")

    // WithError is made priority for the alert message
    log.WithField("alert", alert).WithError(fmt.Errorf("made priority")).Error("default message value")
}

The structure for the OpsGenie alert is documented Here.

logrus-opsgenie-hook's People

Watchers

 avatar  avatar

logrus-opsgenie-hook's Issues

New Trace log level in logrus

Hello, I'm just opening this issue to let you know, the next release of logrus (v1.2.0) will add a new trace level named Trace below Debug.
Here is the PR for reference sirupsen/logrus#844
You may want to take into account this new level.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.