> ## 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.

# util.log to console.log

> Migrate deprecated util.log() to console.log() with timestamp for Node.js DEP0059

This recipe transforms the usage of `util.log()` to use `console.log()` to handle Node.js [DEP0059](https://nodejs.org/api/deprecations.html#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:**

```javascript theme={null}
const util = require("node:util");

util.log("Hello world");
```

**After:**

```javascript theme={null}
console.log(new Date().toLocaleString(), "Hello world");
```

### Multiple Log Statements

**Before:**

```javascript theme={null}
const { log } = require("node:util");

log("Application started");
log("Processing request");
```

**After:**

```javascript theme={null}
console.log(new Date().toLocaleString(), "Application started");
console.log(new Date().toLocaleString(), "Processing request");
```

## Usage

Run this codemod on your project:

```bash theme={null}
npx codemod node/userland/util-log-to-console-log
```

<Tip>
  `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()`.
</Tip>

<Warning>
  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.
</Warning>

## Related Deprecations

* [DEP0059: util.log()](https://nodejs.org/api/deprecations.html#DEP0059)
