Writing/Building clean environment-aware logging utilities.
Essay · Oct 18, 2025

Building clean environment-aware logging utilities.

Deep dive into designing lightweight npm packages in TypeScript for structured logs and automatic production suppression.

Building clean environment-aware logging utilities.

As applications grow, keeping track of application health and tracing user interactions in local development becomes critical. However, verbose logs can clutter the production console, exposing internal application state and degrading web performance. That is why we need environment-aware logging.

"A good developer utility is invisible in production but indispensable in development."

When creating open-source tools like hardlogger, the goal is to provide developers with structured logs—such as distinction between info, success, warnings, and errors—while ensuring that production builds suppress these logs automatically to prevent performance and security overhead.

1. Structuring Node.js and Browser Loggers

Creating a logger requires defining clear log levels and styling them using console colors (ANSI codes in terminal, CSS styles in browsers). By checking the runtime environment (process.env.NODE_ENV), we can automatically strip log logs or silence them entirely in production without forcing the developer to manually wrap console statements.

Using TypeScript ensures that developers get full autocompletion and type-safety when utilizing logger functions across their backend and frontend codebase.

← Back to Writing