Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt

Use this file to discover all available pages before exploring further.

This recipe transforms the usage of util.log() to use console.log() to handle Node.js DEP0059.

What It Does

This codemod replaces:
  • util.log() calls with console.log() including timestamp formatting
  • Removes unnecessary util imports when no longer needed

Before/After

Before:
const util = require("node:util");

util.log("Hello world");
After:
console.log(new Date().toLocaleString(), "Hello world");

Multiple Log Statements

Before:
const { log } = require("node:util");

log("Application started");
log("Processing request");
After:
console.log(new Date().toLocaleString(), "Application started");
console.log(new Date().toLocaleString(), "Processing request");

Usage

Run this codemod on your project:
npx codemod node/userland/util-log-to-console-log
util.log() automatically prefixed messages with a timestamp. The codemod preserves this behavior by adding new Date().toLocaleString() as the first argument to console.log().
If you’re using a structured logging library, you may want to review the transformed code and replace console.log() with your logger’s timestamp functionality instead.

Build docs developers (and LLMs) love