Skip to main content
Bun implements the standard Console API with enhanced formatting, colors, and object inspection. It’s compatible with Node.js and browsers.

Basic Logging

console.log()

Log messages to stdout:

console.error()

Log errors to stderr:

console.warn()

Log warnings to stderr:

console.info()

Log informational messages:

console.debug()

Log debug messages:

Formatting

Format Specifiers

Multiple Arguments

Object Inspection

Default Inspection

Deep Inspection

Control inspection depth:
Set depth with environment variable:
Or in bunfig.toml:

Arrays

Functions

Classes

Grouping

console.group()

Create collapsible groups:

console.groupCollapsed()

Create collapsed groups:

Tables

console.table()

Display data as a table:

Select Columns

Objects as Tables

Timing

console.time()

Measure execution time:

console.timeLog()

Log intermediate times:

Multiple Timers

Counting

console.count()

Count function calls:

console.countReset()

Reset counter:

Labeled Counters

Assertions

console.assert()

Log error if assertion fails:

With Objects

Stack Traces

console.trace()

Print stack trace:

Clearing

console.clear()

Clear console (terminal only):

Colors

Bun automatically colors output in terminals:
Disable colors:
Or:

Custom Inspection

inspect Symbol

toJSON()

Best Practices

  1. Use appropriate log levels
  2. Group related logs
  3. Use timers for performance
  4. Table for structured data
  5. Assertions for debugging

Production Logging

For production apps, consider using a logging library:

Platform Differences

Bun vs Node.js

  • Colors: Bun has better default colors
  • Performance: Bun’s console is faster
  • Depth: Bun defaults to depth 2, Node to unlimited

Bun vs Browsers

  • Streams: Bun writes to stdout/stderr, browsers to DevTools
  • Styling: CSS styling (%c) only works in browsers
  • Persistence: Browser console persists between reloads

API Reference

Logging Methods

Grouping

Tables

Timing

Counting

Other