DEV Community

Theo Gravity
Theo Gravity

Posted on

Taking pretty printing of logs to the next level with LogLayer

LogLayer, the modern logging library for Javascript / Typescript that supports shipping logs to loggers like Pino / Winston and SaaS providers like DataDog, now has a powerful pretty printing feature offered by the Pretty Terminal Transport:

Pretty Printing in LogLayer

  • 🔍 Interactive Selection Mode - Browse and inspect logs in a full-screen interactive view
  • 📝 Detailed Log Inspection - Examine individual log entries with formatted data and context
  • 🔎 Search/Filter Functionality - Find specific logs with powerful filtering capabilities
  • 💅 JSON Pretty Printing - Beautifully formatted structured data with syntax highlighting
  • 🎭 Configurable Themes - Choose from pre-built themes or customize your own colors

Try it out

npm install loglayer @loglayer/transport-pretty-terminal serialize-error

import { LogLayer } from 'loglayer';
import { getPrettyTerminal } from '@loglayer/transport-pretty-terminal';
import { serializeError } from "serialize-error";

// Create LogLayer instance with the transport
const log = new LogLayer({
  errorSerializer: serializeError,
  transport: [
    getPrettyTerminal()
  ],
});

// Start logging!
log.withMetadata({ foo: 'bar' }).info('Hello from Pretty Terminal!');
Enter fullscreen mode Exit fullscreen mode

Simple View

You start out in the simple view, where your logs will print out. You can pause the log stream with "P".

LogLayer Pretty Print Simple View

Selection / search view

Pressing up or down in the simple view will switch to the selection / search view, where you can search through your logs:

LogLayer Pretty Print Selection View

Start typing to filter out logs:

LogLayer Pretty Print Filtering Logs

Detailed view

This is useful for very nested JSON data or arrays. Selecting a log entry from the selection view will bring up the detailed view:

LogLayer Pretty Print Detailed View

You can scroll through the data, and use keyboard commands like "C" to expand out arrays to see the underlying data in them.

JSON view

Pressing "J" in the detailed view will print out the raw JSON, giving you an opportunity to properly copy the JSON data for use elsewhere:

LogLayer Pretty Print JSON view

For more information

For using LogLayer in general, visit the site to get started.

If you want to learn more about the different themes (including creating your own), and keyboard shortcuts for the pretty print, check out the Pretty Terminal Transport documentation.

Top comments (0)