Skip to Content

Logging

Let’s look at how to suggest improvements for logging in code reviews. We’ll show you a simple example and explain why the feedback matters.

The Scenario

A developer has written code to handle user data. The code works but could benefit from better logging.

processUser.ts
// Before function processUser(userId: string) { console.log('Processing user:', userId) const user = db.getUser(userId) console.log('User data:', user) return user }

PR Comment

Choose the comment that you think is the most constructive and helpful.

// After function processUser(userId: string) { logger.info('Starting user processing', { userId }) try { const user = db.getUser(userId) logger.info('User retrieved successfully', { userId }) return user } catch (error) { logger.error('Failed to process user', { userId, error }) throw error } }

Click here to learn more

Improvements

1. Log Quality

  • Appropriate log levels (info, error)
  • Structured data for better parsing
  • Clear context in each log

2. Debugging

  • Easier to track issues
  • Better error context
  • Clearer application flow

3. Monitoring

  • Better system visibility
  • Easier to analyze logs
  • Better performance tracking

Tips

1. Start Positive

  • Acknowledge the working code
  • Show you understand the current approach
  • Example: “Great work on the user processing!“

2. Explain the Benefits

  • Why does logging matter?
  • How does it help?
  • Example: “This helps with debugging”

3. Be Specific

  • Suggest concrete improvements
  • Explain why they matter
  • Example: “Adding structured logging helps with monitoring”

4. Keep It Friendly

  • Focus on improvement, not criticism
  • Use encouraging language
  • Example: “Thanks for considering logging!”

Common Pitfalls to Avoid

1. Being Too Critical

  • ❌ “This logging is terrible.”
  • ✅ “Good work! Here’s how we can make it even more helpful.”

2. Not Explaining Why

  • ❌ “Add better logging.”
  • ✅ “Adding structured logging helps with debugging.”

3. Ignoring the Positive

  • ❌ “This needs better logging.”
  • ✅ “Great work! Here’s how we can make it even more maintainable.”

Remember: The goal is to help your teammate write better code while maintaining a positive and collaborative environment!

Last updated on
Exception HandlingTest Quality