Back to all reviewers

Use structured logging consistently

browserbase/stagehand
Based on 5 comments
TypeScript

Always use the established logging framework instead of console.log or ad-hoc logging approaches. This ensures consistent log formatting, proper log levels, and better log management across the application.

Logging TypeScript

Reviewer Prompt

Always use the established logging framework instead of console.log or ad-hoc logging approaches. This ensures consistent log formatting, proper log levels, and better log management across the application.

When logging errors, include contextual information like error traces, messages, and auxiliary data to make logs more informative for debugging. For components that need logging capabilities, inherit or inject the logger from the main application rather than creating separate logging mechanisms.

Example of what to avoid:

console.log(options.messages);
console.log(tree);

Example of proper structured logging:

this.logger({
  category: "debug",
  message: "Processing options messages",
  auxiliary: { messageCount: options.messages.length }
});

this.stagehandLogger.error(
  "The browser context is undefined. This means the CDP connection to the browser failed"
);

This approach provides better log filtering, formatting, and integration with log management systems while maintaining consistency across the codebase.

5
Comments Analyzed
TypeScript
Primary Language
Logging
Category

Source Discussions