Ccodemod

codemod/replace-console-log-with-vivid-trail-rj9w

Replace console.log with OTel logger

transformationmigrationloggingopentelemetryconsole
Public
0 executions

Run locally

npx codemod @codemod/replace-console-log-with-vivid-trail-rj9w

@codemod/replace-console-log-with-vivid-trail-rj9w

Replace console.log with OTel logger

What It Does

This codemod rewrites standalone console.log(...) statement calls in the server-side parts of codemod/codemod-app to the repository's existing OpenTelemetry logger API from @codemod.com/otel.

It uses the repo's established shape:

ts

Target Paths

  • apps/worker/src/**
  • packages/api/src/**
  • apps/nextjs/src/instrumentation.*
  • apps/nextjs/src/instrumentation-node.*
  • apps/nextjs/src/middleware.*

Skips

  • comments and string literals that merely mention console.log
  • console.log calls used inside larger expressions instead of standalone statements
  • client-side Next.js files with a top-level "use client" directive
  • apps/nextjs/src/app/(studio)/studio/_hooks/_data/default/**
  • apps/nextjs/scripts/**
  • apps/website/**
  • apps/promotional-videos/**
  • files outside the repo areas that already show @codemod.com/otel usage conventions

Rewrite Rules

Single message

ts

becomes:

ts

String or template message with extra args

ts

becomes:

ts

No leading string-ish message

ts

becomes:

ts

Import Handling

  • reuses an existing logger import from @codemod.com/otel
  • extends an existing @codemod.com/otel named import when logger is missing
  • adds a new @codemod.com/otel import when needed
  • aliases to logger as otelLogger when the file already binds logger

Assumptions

  • The codemod is intentionally repository-aware, not a generic console.log migration.
  • It only rewrites files where using @codemod.com/otel is consistent with the repo's current server-side logging conventions.
  • For Next.js, it stays conservative and only targets clearly server-side entry files.

Installation

bash

Usage

bash

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.