@tinyhttp/logger
Minimal and flexible HTTP request logger middleware for tinyhttp and Node.js.
Repository Health
Technical Analysis
@tinyhttp/logger is a small HTTP logging middleware built for the tinyhttp web framework but usable with any Node.js http-compatible request/response pair. It hooks into the response finish event to print a per-request log line showing method, status code, status message, and URL, with optional colorized output for 2xx/4xx/5xx responses.
Beyond the basics, it supports timestamped log lines (formatted via dayjs), emoji status badges for quick visual scanning, IP address logging, log-level tagging, and a route-ignore list to keep noisy paths (like health checks) out of the log stream. A companion FileLogger class lets you additionally stream log lines to a file, creating the target directory and file automatically if they don’t exist.
The package ships as ESM-only with full TypeScript type definitions, and its API surface is a single logger(options) factory function plus a LogLevel enum, making it easy to drop into an existing middleware stack without any additional configuration.
What You Get
- A
logger(options)middleware factory that logs method, status, message, and URL for every request - Colorized console output that differentiates 2xx (cyan), 4xx (red), and 5xx (magenta) responses
- Optional emoji status badges (via
http-status-emojis) for at-a-glance status scanning - Configurable timestamp formatting powered by dayjs, with a custom format string option
- A
LogLevelenum (error,warn,trace,info,log) for tagging log output by severity - Built-in
FileLoggersupport to additionally stream logs to a file, auto-creating directories as needed - A
ignoreoption to skip logging for specific route path prefixes
Common Use Cases
- Adding request/response logging to a tinyhttp or Node.js HTTP server during development
- Producing colorized, human-readable console logs for local debugging
- Writing structured request logs to a file for later inspection or log aggregation
- Filtering out noisy routes (e.g. health-check or polling endpoints) from log output
- Tagging log lines with severity levels when routing them to different output destinations
Under The Hood
Architecture
The package is a single-purpose middleware factory: logger(options) returns a request handler that attaches a listener to the response object’s finish event rather than logging synchronously as the request comes in, so the logged status code and message always reflect the final response state. All formatting logic is centralized in a compileArgs helper that builds up an array of log tokens (timestamp, IP, emoji, method, status, message, URL) which is then joined into a single string, keeping the color-branching logic in logger itself separate from token assembly. File output is delegated entirely to a separate FileLogger class in filelogger.ts, so the core middleware has no knowledge of file-system concerns beyond checking whether a filename was configured. This is a flat, two-module design with no internal dependency injection or plugin system, appropriate for the narrow scope of the package.
Tech Stack
Written in TypeScript targeting ESM only, with colorette for terminal colors, dayjs for timestamp formatting, and http-status-emojis for status-to-emoji mapping. It depends on Node’s built-in http module types (IncomingMessage/ServerResponse) rather than any specific framework, though the README and devDependencies show it’s built and tested against @tinyhttp/app. Builds run through the TypeScript compiler (tsc), package management and CI run on Bun, and linting/formatting is handled by Biome rather than ESLint/Prettier.
Code Quality
Tests live under tests/ and use Vitest with supertest-fetch to make real HTTP requests against a running @tinyhttp/app instance, covering timestamp formatting, log levels, custom output callbacks, route ignoring, file logging, ANSI color codes per status class, and emoji badges. Coverage is measured via vitest run --coverage and reported to Coveralls in CI. Error handling is minimal by design — FileLogger’s internal fsAccess check swallows errors to determine file existence, which is a deliberate existence-check pattern rather than silent failure. Typing is comprehensive (LoggerOptions as a Partial<{...}> type, a LogLevel enum), and Biome enforces consistent formatting and lint rules across the small codebase.
What Makes It Unique
Rather than reinventing an output pipeline, the package layers small pluggable behaviors — color, emoji, timestamp format, IP logging, level tagging, route ignoring, and file output — on top of a single finish-event hook, letting consumers opt into exactly the amount of formatting they need. Its niche differentiator versus general-purpose loggers like Pino or Winston is that it’s purpose-built as thin HTTP request-logging middleware for the tinyhttp ecosystem rather than a general logging library, trading breadth for a minimal footprint and near-zero configuration to get readable request logs.