HubSpot Engineering

Latest posts

Writing lately

Styling console.log

Console.log is one of the simplest, and most powerful, tools frontend developers have. Turns out, it's not quite as simple as we thought. Console messages can be formatted using CSS. You could, for example, make your error messages larger:

Browser console: console.error styled font-size:20pt prints “The Splines Failed to Reticulate!” in large red letters.

You could give your log messages a pleasant shadow:

Browser console: console.log styled with a grey text-shadow prints “Launching nanobot control subsystem...” with a soft shadow.

The styles don't have to apply to the whole message:

Browser console: console.log with %c just before Loaded prints “System Status: Loaded” with only the word Loaded in bold.

Each %c resets the styles:

Browser console: a single console.log with a %c before each part prints “Note:” in red, “The security color of the day is” in plain text and “orange” in bold orange.

Add some formailty to your messages:

Browser console: console.log styled with a cursive font-family prints “There was an error loading the user. Fonts loaded just fine tho.”

Text is boring, use images:

Browser console: console.log with an image URL in its CSS prints the Backbone.js logo as a large picture.

Include charts in your console logging:

Browser console with a chart drawn in the log: hundreds of thin grey bars in a jagged band of peaks and valleys.

Even better, anything you can draw on a canvas, you can draw in the console.

Newsletter

For Agents

View Markdown

Share

More posts

Moving Mountains: How We Migrated from Enzyme to React Testing Library

How we migrated 76,000 tests from Enzyme to React Testing Library, modernizing our stack and allowing teams to ship changes with more confidence.

A Tech Guide to Web Accessibility: Why It Matters and How to Improve It

Web accessibility is a crucial aspect of building modern websites and applications, which helps ensure that people with disabilities have access to the same information and services as people without disabilities.

Immutability and Its (Potential) Impact on Performance

We recently encountered a performance bug that challenged the use of immutability in our frontend applications.