Skip to content

Fix custom logger conflicts with CrewAI verbose logging (#3197) #3198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fix custom logger conflicts with CrewAI verbose logging (#3197)

Summary

This PR fixes issue #3197 where custom Python loggers don't work when CrewAI's verbose=True is enabled. The problem occurred because Rich's Live console formatter captures stdout/stderr when active, preventing custom logger output from being displayed.

Root Cause: The ConsoleFormatter.print() method wasn't properly pausing Rich Live sessions when printing non-Tree content (like custom logger output), causing the output to be suppressed.

Solution: Modified the print method to temporarily pause the Live session when printing non-Tree content, print the content normally (allowing custom loggers to work), then resume the Live session.

Review & Testing Checklist for Human

  • End-to-end verification: Test actual CrewAI workflows with verbose=True and custom Python loggers to ensure logging output appears correctly
  • Rich Live formatting preservation: Verify that CrewAI's own live console formatting (trees, progress indicators) still works properly during verbose mode
  • Edge case testing: Test scenarios like rapid custom logging, multiple pause/resume cycles, and different types of Rich renderables
  • Performance impact assessment: Check if the additional logic in the print method causes noticeable performance regression during verbose logging
  • Integration testing: Run CrewAI's existing test suite to ensure no regressions in core functionality

Recommended Test Plan:

  1. Create a simple CrewAI workflow with custom tools that use Python's logging module
  2. Run with verbose=False - custom logs should appear
  3. Run with verbose=True - custom logs should still appear alongside CrewAI's live formatting
  4. Verify CrewAI's own progress trees and status updates work normally

Diagram

%%{ init : { "theme" : "default" }}%%
graph TB
    Issue["Issue #3197<br/>Custom loggers suppressed<br/>when verbose=True"] --> CF["src/crewai/utilities/events/<br/>utils/console_formatter.py"]:::major-edit
    
    CF --> Print["print() method"]:::major-edit
    CF --> Pause["pause_live_updates()"]:::major-edit  
    CF --> Resume["resume_live_updates()"]:::major-edit
    CF --> TreeAttr["_paused_tree attribute"]:::major-edit
    
    Print --> LiveCheck{Live session active?}
    LiveCheck -->|Non-Tree content| PauseFlow["Pause → Print → Resume"]
    LiveCheck -->|Tree content| NormalFlow["Normal Rich rendering"]
    
    Tests["tests/test_custom_logger_fix.py"]:::major-edit --> CF
    Repro["test_logging_reproduction.py"]:::major-edit --> CF
    
    Logger["Python logging module"]:::context --> Print
    Rich["Rich Live console"]:::context --> CF
    
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit  
        L3["Context/No Edit"]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Testing Limitation: Integration tests failed due to OpenAI API authentication issues, so end-to-end verification with actual LLM calls is needed
  • Backward Compatibility: All existing ConsoleFormatter pause/resume tests pass, indicating compatibility with current behavior
  • Implementation Details: The fix adds safety checks to only restore Live sessions with valid Rich renderables (objects with __rich_console__ method)

Link to Devin run: https://app.devin.ai/sessions/2efed7ad99014cfda6649c9b2cb6a700
Requested by: João ([email protected])

devin-ai-integration bot and others added 2 commits July 21, 2025 12:15
- Modified ConsoleFormatter.print() to pause Live sessions when printing non-Tree content
- Added _paused_tree attribute to store tree state during pauses
- Updated pause_live_updates() and resume_live_updates() methods to properly restore Live sessions
- Added comprehensive tests covering the logging conflict scenario
- Fixes issue #3197 where custom Python loggers were suppressed when verbose=True

The fix ensures custom loggers work properly while preserving CrewAI's live formatting functionality.

Co-Authored-By: Jo\u00E3o <[email protected]>
This test demonstrates the original problem where custom Python loggers
don't work when CrewAI's verbose=True is enabled, and can be used to
verify the fix works correctly.

Co-Authored-By: Jo\u00E3o <[email protected]>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Remove unused sys and redirect_stderr imports from test_simple_logging_fix.py
- Remove unused sys and pytest imports from tests/test_custom_logger_fix.py
- All lint checks now pass locally

Co-Authored-By: Jo\u00E3o <[email protected]>
Copy link
Contributor Author

Closing due to inactivity for more than 7 days. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants