Make Your Logs Work for You

The days of logging in to servers and manually viewing log files are over. SolarWinds® Papertrail™ aggregates logs from applications, devices, and platforms to a central location.

View Technology Info

FEATURED TECHNOLOGY

Troubleshoot Fast and Enjoy It

SolarWinds® Papertrail™ provides cloud-based log management that seamlessly aggregates logs from applications, servers, network devices, services, platforms, and much more.

View Capabilities Info

FEATURED CAPABILITIES

Aggregate and Search Any Log

SolarWinds® Papertrail™ provides lightning-fast search, live tail, flexible system groups, team-wide access, and integration with popular communications platforms like PagerDuty and Slack to help you quickly track down customer problems, debug app requests, or troubleshoot slow database queries.

View Languages Info

FEATURED LANGUAGES

TBD - APM Integration Title

TBD - APM Integration Description

TBD Link

APM Integration Feature List

TBD - Built for Collaboration Title

TBD - Built for Collaboration Description

TBD Link

Built for Collaboration Feature List

Blog > Papertrail + Slack:

Papertrail + Slack:

Keeping On Top of Your Most Important Logs

Posted by By Papertrail Team on September 12, 2022

One of the most important pieces of operating any application stack is making sure you’re aware of the logging events occurring on your running systems. If your development team is like most, then you collaborate with your colleagues using Slack.

Being successful while building and operating software includes looking for ways to implement high-visibility operations within your team communication platform.

Of course, you can’t manually watch your logs to get the most critical information to your team in real time. This is where Papertrail and Slack—working together—come in. In this article, we’ll look at how you can set up an automated alert for specific search queries in Papertrail, which will update your team immediately in Slack.

Step 1: Create a Sample Application for Logging

For the purposes of this article, we’ll create an extremely simple Node.js Express application. It will emit a log entry at the INFO level for the only route it matches on. However, it will emit an ERROR level log for any other request. While you could use any logging method you like, our simple demo code looks like this:

index.js

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
  console.log(`INFO: Logger app accessed on the root route`)
})

app.all('*', (req, res) => {
  res.status(404).send(`ERROR: There's no route here with request method ${req.method}`)
  console.log(`ERROR: ${req.method} attempted at non-existent route`)
})

app.listen(port, () => {
  console.log(`INFO: Logger app listening on port ${port}`)
})

As you can see, the server only has one successful route—listening for GET requests on the root path. Any other route will log (and respond with) an error. If you’ve properly installed Express, then you can run the application with the following command:

$ node index.js

However, since we’re planning to send our logs to Papertrail, we’ll run this command instead:

$ node index.js >> logger.log

This dumps the console output into a file called logger.log in your project’s working directory. Feel free to send the output elsewhere if it’s more convenient for you. But if your application runs and logs as you’d expect, then let’s move on.

Step 2: Configure Papertrail

First, sign up for a Papertrail account. Once you configure your account, you’ll be guided on how to send log data to the Papertrail servers. If you choose to aggregate application log files, then the setup screen will look similar to this:

Setting up a new log sender in Papertrail.
Sending log data to Papertrail

Choose the platform you’re running on, then install remote_syslog2. Finally, update the command you received for sending your logs to Papertrail, pointing to the full path of the logger.log file we created (replacing /path/to/your/file.log given in the example).

With Papertrail logging set up, you can visit any route for your Node.js app in your browser. If remote_syslog2 runs without an error, then the setup page should update with a notice showing a log has been received. If you go to the Events page, then you’ll start to see logs from your Node.js app show up. Visit a few routes for your Node.js application, and then see how your Events page updates.

In a full implementation of Papertrail, you could set up system and application logs from many different sources, and Papertrail would indicate the source and origin of all logs it aggregates. However, for our demo, we only need this simple example.

Step 3: Set Up Your Slack Alert

Alerts in Papertrail are based on searches across your aggregated log data. Saving a search is simple. If you type something in the search box at the bottom of the Events page, then Papertrail will automatically filter results down to match your search.

Save a search in Papertrail to setup a notification.
A log search in Papertrail event viewer.

For our example, we’re looking for logs starting with the ERROR: string. If you click the bookmark icon, you’ll be prompted to save your search.

Saving a search in Papertrail
The Save Search window in Papertrail

The search we’re making is pretty simple, but once we save it, we have many options for what to do next.

Papertrail and Slack integration option
Alerting options in Papertrail

As you can see, Slack is a prominent option under the Chat heading. Clicking on it gives us a few important options for what to do next. We merely need to provide a webhook URL for our Slack instance:

Providing the Webhook URL enables Papertrail and Slack to work together
Defining the alert conditions in Papertrail

We can follow the link to “Create a new Papertrail integration in Slack.” After following the instructions in Slack, we’ll end up with a webhook URL, which we paste into this Papertrail integration. From there, Papertrail will start following this search and trigger the alert we specified. Here’s a screenshot of what a Papertrail alert looks like in Slack,

Papertrail Alert in Slack

Simple, right? In three quick steps, we’ve done the following:

  1. Set up our application to output log events to a file.
  2. Set up remote_syslog2 to stream the contents of that log file to Papertrail.
  3. Set up and saved a query in Papertrail, which alerts us by sending a notification to Slack.

Conclusion

Don’t you love it when the pieces fit together so perfectly and easily? Papertrail integrations—like alert notifications to Slack—are great for keeping your team in the loop on log alerts mattering the most. The technology makes it easy. All you need to do is make some decisions about what alerts you and your team need to receive and the frequency at which you need to receive them.

You can get started on aggregating all your logs today and setting up the alerts you need. This will help your team keep a close watch on your systems, and they can do so within the comfort of their Slack workspace. Get started with your free trial of Papertrail today.