0
0
Ruby on Railsframework~30 mins

Logging and monitoring in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Logging and Monitoring in Rails
📖 Scenario: You are building a simple Rails application that tracks user actions. To keep your app healthy and debug issues quickly, you need to set up logging and monitoring.
🎯 Goal: Learn how to create a basic log entry, configure log level, and display logs in the Rails console.
📋 What You'll Learn
Create a log entry with a specific message
Set the log level to :info
Write a method that logs user actions
Print the log output to the console
💡 Why This Matters
🌍 Real World
Logging helps developers track what happens in their applications. Monitoring logs is like checking a car's dashboard to see if everything is working well.
💼 Career
Understanding logging and monitoring is essential for DevOps roles to maintain application health and troubleshoot issues quickly.
Progress0 / 4 steps
1
Create a logger instance
Create a variable called logger and assign it a new Logger instance that writes to STDOUT.
Ruby on Rails
Need a hint?

Use Logger.new(STDOUT) to create a logger that outputs to the console.

2
Set the log level to info
Set the logger variable's log level to Logger::INFO.
Ruby on Rails
Need a hint?

Use logger.level = Logger::INFO to set the log level.

3
Write a method to log user actions
Define a method called log_user_action that takes a user and an action string, and uses logger.info to log the message: "User: #{user} performed: #{action}".
Ruby on Rails
Need a hint?

Define a method with two parameters and call logger.info inside it.

4
Log a sample user action and display output
Call the log_user_action method with "Alice" as the user and "login" as the action. This should print the log message to the console.
Ruby on Rails
Need a hint?

Call the method with the exact arguments to see the log output.