How We Solved Node's Hard to Use Logs


(actual photo of Node developer using logs)

Nothing makes you feel overhwhelmed quite like logs in the midst of solving a criticial production issue. The raw text, hard to read, hard to search data will leave you questioning which life decisions got you there. And if you were like us, this is an almost daily occurence. Logs are critical to maintaining our apps, yet they can be incredibly difficult to use.

This article shares our solution to Node's noisy, hard-to-use logs: timber. Instantly cutting time to resolution by 80%, allowing developers to focus on delivering features instead of logging, infrastructure, and debugging.

What's the problem with Node logging?

Let's start by looking at a default Express/Morgan log line:

::1 - - [Mon, 09 Oct 2017 23:23:37 GMT] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

Rightfully so, Express defaults to the Apache standard format. It is not Express' job to solve logging, but this certainly isn't doing you any favors. Pointing out the obvious problems:

  1. Unstructured - Unparseable, hard to search.
  2. Unreadable - Noisy, hard to use and read.
  3. Low quality - Lacking request ID, request paramters, and other data.
  4. Inconsistent - Other application logs aren't in the same format.

And then of course you need a way to access, search, and retain these logs. Do you log to a file or STDOUT? Where do you store your logs? How do you ship them? Should you host the service or pay for a hosted one? Ah! I just want to focus on my app, not become a logging expert!

Our solution

Our solution is simple: timber, a library that automatically structures your logs and pairs with a beautiful, easy to use console. It works with Wintston, Bunyan, and Express, and includes HTTP shipping for easy setup. Here's a demo:

App - Demo

Installation

Setup is easy:

  1. Sign up and obtain your API key

  2. Install timber via:

    1
     npm install --save timber
    
  3. And then add the following to your entry file:

    1
    2
    3
     const timber = require('timber');
    
     const transport = new timber.transports.HTTPS('{{my-timber-api-key}}');
    

Get things done with your logs

With great logging comes great powers:

...and more! Checkout our the Timber application docs