Skip to main content

Logger Migration Summary

🎯 Overview

Migrated from console.log to MedusaJS logger for better production logging, log levels, and monitoring.


✅ Files Updated

Subscribers

  • /src/subscribers/social-platform-credentials-encryption.ts
    • All console.loglogger.info
    • All console.errorlogger.error

Workflows

  • /src/workflows/socials/extract-hashtags-mentions.ts
    • Added logger resolution
    • Added try/catch with error logging
    • Detailed extraction metrics

Workflow Steps (Pending)

  • /src/workflows/socials/steps/decrypt-credentials.ts - Partially updated
  • /src/workflows/socials/steps/load-post-with-platform.ts
  • /src/workflows/socials/steps/merge-publish-results.ts
  • /src/workflows/socials/steps/validate-content-compatibility.ts
  • /src/workflows/socials/steps/extract-target-accounts.ts
  • /src/workflows/socials/steps/extract-content.ts
  • /src/workflows/socials/steps/detect-smart-retry.ts
  • /src/workflows/socials/steps/route-to-platform-workflow.ts
  • /src/workflows/socials/steps/update-post-with-results.ts
  • /src/workflows/socials/steps/validate-platform.ts
  • /src/workflows/socials/steps/determine-content-type.ts
  • /src/workflows/socials/steps/encrypt-platform-tokens.ts (can be deleted)

📝 Logger Pattern

Standard Pattern

export const myStep = createStep(
"step-name",
async (input, { container }) => {
const logger = container.resolve("logger")

logger.info("[Step Name] Starting...")

try {
// Step logic
logger.info("[Step Name] ✓ Success message")
return new StepResponse(result)
} catch (error) {
logger.error("[Step Name] ❌ Error:", error)
throw error
}
}
)

Log Levels

  • logger.info() - Normal operation, success messages
  • logger.warn() - Warnings, deprecated features
  • logger.error() - Errors, failures
  • logger.debug() - Detailed debugging (use sparingly)

🎯 Benefits

  1. Structured Logging - Proper log levels for filtering
  2. Production Ready - Integrates with log aggregation tools
  3. Better Monitoring - Can track errors and performance
  4. Consistent Format - All logs follow same pattern
  5. Environment Aware - Different log levels per environment

🔄 Migration Checklist

Phase 1: Critical Components ✅

  • Event subscribers
  • Main workflows
  • Hashtags/mentions extraction

Phase 2: Workflow Steps (In Progress)

  • decrypt-credentials (partial)
  • All other workflow steps

Phase 3: Services & Routes

  • Social provider services
  • API routes
  • Webhook handlers

📊 Impact

Before:

console.log("[Step] Message")  // No log levels
console.error("Error:", error) // Limited context

After:

logger.info("[Step] Message")   // Proper log level
logger.error("[Step] ❌ Error:", error) // Better context

🚀 Next Steps

  1. Complete workflow steps migration
  2. Update services and routes
  3. Configure log levels per environment
  4. Set up log aggregation (optional)
  5. Add monitoring dashboards (optional)

Status: In Progress
Last Updated: November 19, 2025
Completed: 3/15 files