Skip to content

Conversation

@zshanhui
Copy link

@zshanhui zshanhui commented Dec 2, 2025

Description

Describe your changes in detail (optional if the linked issue already contains a detailed description of the changes).

Fixes #3351
This PR moves the print logs to WorkforceLogger callback, add abstract method log_message to WorkforceCallback. Replaces a couple print statements for demonstration and plan to replace the remaining print statements in a followup PR.

Checklist

Go over all the following points, and put an x in all the boxes that apply.

  • I have read the CONTRIBUTION guide (required)
  • I have linked this PR to an issue using the Development section on the right sidebar or by adding Fixes #issue-number in the PR description (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and uv lock
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed:
  • I have added examples if this is a new feature

If you are unsure about any of these, don't hesitate to ask. We are here to help!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zshanhui zshanhui changed the title update WorkforceLogger with log_message update WorkforceLogger with log_message Fixes #3351 Dec 2, 2025
@zshanhui zshanhui marked this pull request as ready for review December 2, 2025 16:09
@zshanhui zshanhui changed the title update WorkforceLogger with log_message Fixes #3351 update WorkforceLogger with log_message Dec 2, 2025
print(event.message)
color = _COLOR_MAP.get(event.level)
colored_message = f"{color}{event.message}{Fore.RESET}"
print(colored_message)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use the logger.info/warning/error. module here, the info and success levels does not log to the console out which changes the original behavior of the print statements. do we want to use logger instead?

class WorkforceEventBase(BaseModel):
model_config = ConfigDict(frozen=True, extra='forbid')
event_type: Literal[
"message_log",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use log instead of message_log for naming consistency

  • task_created -> TaskCreatedEvent
  • log -> LogEvent

class LogEvent(WorkforceEventBase):
event_type: Literal["message_log"] = "message_log"
message: str
level: Literal["info", "warning", "error", "success"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend defining the level parameter with the common logging levels: debug/info/warning/error/critical. each level has a default style

Additionally, the parameter style: Literal["blue", "green", "gray", "xxx" ] | None = None should be added to allow for developer customization.

Comment on lines +76 to +79
if event.level == 'debug':
logger.debug(colored_message)
if event.level == 'info':
logger.info(colored_message)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: the debug and info logs don't show on console out due to minimum=WARNING

@zshanhui zshanhui requested a review from coolbeevip December 3, 2025 15:27
@zshanhui
Copy link
Author

zshanhui commented Dec 3, 2025

i've updated the PR to address the comments and changed to use logger module

Comment on lines +66 to +71
def _get_color_message(self, event: LogEvent) -> str:
r"""Gets a colored message for a log event."""
if event.color is None or event.color not in _COLOR_MAP:
return event.message
color = _COLOR_MAP.get(event.color)
return f"{color}{event.message}{Fore.RESET}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move _get_color_message and _COLOR_MAP into WorkforceCallback. Also rename _COLOR_MAP to __COLOR_MAP to mark it as a private attribute

color = _COLOR_MAP.get(event.color)
return f"{color}{event.message}{Fore.RESET}"

def log_message(self, event: LogEvent) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the default WorkforceLogger, we should keep using print to ensure refactoring doesn’t change the output behavior.

@waleedalzarooni waleedalzarooni self-requested a review December 4, 2025 11:10
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.

[Feature Request] Refactor Workforce to Decouple Logging via Callbacks

2 participants