nyelonong / panics

Simple package to catch & notify your panic or exceptions via slack or save into files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panics GoDoc CircleCI GoReportCard

Simple package to catch & notify your panic or exceptions via slack or save into files.

import "github.com/tokopedia/panics"

Configuration

panics.SetOptions(&panics.Options{
	Env:             "TEST",
	SlackWebhookURL: "https://hooks.slack.com/services/blablabla/blablabla/blabla",
	Filepath:        "/var/log/myapplication", // it'll generate panics.log

	Tags: panics.Tags{"host": "127.0.0.1", "datacenter":"aws"},
})

Capture Custom Error

panics.Capture(
    "Deposit Anomaly",
    `{"user_id":123, "deposit_amount" : -100000000}`,
)

Capture Panic on HTTP Handler

http.HandleFunc("/", panics.CaptureHandler(func(w http.ResponseWriter, r *http.Request) {
	panic("Duh aku panik nih guys")
}))

Capture Panic on httprouter handler

router := httprouter.New()
router.POST("/", panics.CaptureHTTPRouterHandler(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    panic("Duh httprouter aku panik nih guys")
}))

Capture Panic on negroni custom middleware

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	panic("Duh aku panik nih guys")
})
negro := negroni.New()
negro.Use(negroni.HandlerFunc(CaptureNegroniHandler))

Example

Slack Notification

Notification Example

Authors

About

Simple package to catch & notify your panic or exceptions via slack or save into files.


Languages

Language:Go 100.0%