Giter VIP home page Giter VIP logo

directmailers-loghook's Introduction

directmailers-loghook for logrus

Have you ever wanted to get a postcard in the mail the last time your program crashed?

This is a hook for logrus that will send your logs to you (or some other address of your choosing) in a letter or post card in the mail.

Requirements

As the name suggests, this library uses the directmailers API for sending letters and postcards. So you'll need an account with them. Signing up is free, and they'll give you $10 in credit when you do, which should be enough to send about 17 postcards (see https://print.directmailers.com/tour/pricing/).

Installation and usage

go get github.com/kimbo/directmailers-loghook/...

Then you can initialize the hook like this:

package main

import (
	"errors"
	"os"

	"github.com/kimbo/directmailers-loghook/api"
	"github.com/kimbo/directmailers-loghook/hook"
	"github.com/sirupsen/logrus"
)

func main() {
    // get these at https://dashboard.directmailers.com/settings
	user := os.Getenv("DIRECTMAILER_USERNAME")
	pass := os.Getenv("DIRECTMAILER_PASSWORD")

	h := hook.New(user, pass, hook.Config{
		DryRun: true,
		MaxLevel: logrus.ErrorLevel,
		MailType: hook.Postcard, // or hook.Letter
		From: api.SenderDetails{
			Name:         "my-application",
			AddressLine1: "123 N 456 W",
			AddressLine2: "Apt 789",
			City:         "San Francisco",
			State:        "CA",
			Zip:          "12345",
		},
		To: api.RecipientDetails{
			Name:         "The White House", // why not send you logs to the President?
			AddressLine1: "1600 Pennsylvania Ave",
			AddressLine2: "",
			City:         "Washington",
			State:        "DC",
			Zip:          "20006",
		},
	})
	logrus.AddHook(h)

	doSomething := func() error {
		return errors.New("I was running and tripped over the waste basket and now there's garbage everywhere")
	}

	if err := doSomething(); err != nil {
		// that's another $0.56, errors get expensive quickly
		logrus.Errorf("Oh no, we have a problem: %v", err)
	}
}

Roadmap

  • Improve default template for letters and postcards (right now it's just <p>log message goes here</p>)
  • Clean way to use custom templates

Limitations

I don't know this for sure, but I suspect directmailers only will send mail in the United States of America.

directmailers-loghook's People

Contributors

kimbo avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.