explaingit

trentm/node-bunyan

7,212JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Bunyan is a Node.js logging library that writes every log entry as a single JSON line, making server logs machine-readable and filterable with its included command-line tool.

Mindmap

mindmap
  root((node-bunyan))
    What it does
      JSON log lines
      Structured records
      Multi-stream output
    Log levels
      trace debug info
      warn error fatal
    Features
      Child loggers
      Rotating files
      CLI viewer
    Audience
      Node.js developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace console.log in a Node.js app with structured JSON logs searchable by level, time range, or any custom field.

USE CASE 2

Stream logs to multiple destinations at once, file, stdout, and a monitoring service, each at a different severity level.

USE CASE 3

Use child loggers to automatically tag every log line from a request or session with shared context fields like a request ID.

USE CASE 4

Pipe raw JSON log output through the bunyan CLI to get colorized, human-readable output during local development.

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min
License not stated in the explanation.

In plain English

Bunyan is a logging library for Node.js applications. Its central idea is that server logs should be structured data rather than free-form text, so every log entry it produces is a single line of JSON. Each line includes fields like the application name, process ID, hostname, timestamp, severity level, and the message you asked it to log. Because the output is machine-readable JSON, it is easy to search and filter with other tools. The library has a small API. You create a logger by calling bunyan.createLogger with a name and optional settings, then call methods named after severity levels: trace, debug, info, warn, error, and fatal. Each call writes a JSON line to wherever you have configured the logger to write. You can also pass extra fields alongside the message, and those fields get folded into the JSON record. Error objects are handled specially so their stack traces are captured in a structured way. Bunyan comes with a command-line tool, also called bunyan, that reads the raw JSON log output and displays it in a human-friendly, colorized format. The CLI can also filter records by level, time range, or any custom field, so you can search through logs without relying on grep over plain text. The streams system controls where log output goes. You can write to a file, to stdout, to a rotating file (where old log files are moved aside automatically), or to any custom destination. Loggers can fan out to multiple streams at different severity levels, for example writing everything to a file but only warnings and above to a monitoring service. Child loggers let you create a specialized copy of an existing logger that inherits its settings but adds extra fields automatically to every record it writes. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Set up Bunyan in my Node.js Express app to log all incoming requests as JSON with method, URL, status code, and response time fields.
Prompt 2
How do I create a Bunyan child logger that automatically adds a requestId field to every log line inside a specific request handler?
Prompt 3
Configure Bunyan to write ERROR and above to a rotating log file and write everything to stdout in my Node.js service.
Prompt 4
Show me how to use the bunyan CLI to filter a stream of JSON logs to show only ERROR level entries from the past hour.
Prompt 5
How do I log a JavaScript Error object with Bunyan so the stack trace is captured in the JSON output as a structured field?
Open on GitHub → Explain another repo

← trentm on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.