Logging with structured formats
📖 Scenario: You are building a simple Node.js application that logs user actions. To make logs easy to read and analyze, you will use structured JSON format for logging.
🎯 Goal: Create a Node.js script that logs user actions as JSON objects with clear keys for user, action, and timestamp.
📋 What You'll Learn
Create an object representing a user action with keys
user, action, and timestampAdd a configuration variable for the current time in ISO format
Use a function to create a structured log object combining user, action, and timestamp
Print the structured log as a JSON string
💡 Why This Matters
🌍 Real World
Structured logging helps teams quickly find and analyze logs in production systems, improving troubleshooting and monitoring.
💼 Career
Understanding structured logging is essential for DevOps roles to maintain reliable and observable applications.
Progress0 / 4 steps