Get your app logging to Slack in 15 minutes

Logs are one of the most under appreciated tools for developers. Without them you are flying blind. Your app could literally be on FIRE and you wouldn’t know!…just kidding…but seriously.

I’m not far from one of the larger code pushes for Pingly dealing with SMS and billing. It contains many moving parts that need to work together in unison to keep things running smoothly. There are important events that I’d like to see in real-time as they happen in Pingly so that I can verify things are in fact running correctly. Enter Slack.

If you haven’t heard about Slack then you may want to check your internet connection. Anyways, here’s the quick-and-dirty way I got Pingly logging to Slack in 15 minutes.

Create a new webhook in Slack

Create webhook page in Slack

I have already created a new channel named #logs and have selected this as the default channel this webhook will post to. Once created, the next page will show you your unique webhook URL to send data to:

https://hooks.slack.com/services/##############

Obviously you shouldn’t share this URL unless you want random people posting stuff into your Slack channel. (App Idea: Slack Roulette? Danger zone)

Post event data to webhook

This is a quick and dirty Ruby one-liner to post data with. There are also many great Slack gems and libraries available as well.

Swap out this Ruby code for whatever language you are using

Just replace the webhook URL with your own and set the payload text to something descriptive for your log event. You can also customize the payload sent to Slack to include links and images.

Voila! Below you can see Pingly’s bot “Pong” doing its job dutifully and telling me it’s lunch time and that we’re rolling in the dough.

Hope you found this post helpful!

Like what you read? Give Noah Everett a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.