camel icon indicating copy to clipboard operation
camel copied to clipboard

[Feature Request] Refactor Workforce to Decouple Logging via Callbacks

Open coolbeevip opened this issue 1 month ago • 3 comments

Required prerequisites

  • [x] I have searched the Issue Tracker and Discussions that this hasn't already been reported. (+1 or comment there if it has.)
  • [x] Consider asking first in a Discussion.

Motivation

The camel.societies.workforce.workforce.Workforce class currently uses direct print() calls for logging informational messages, warnings, and errors (e.g., when a worker is created or a task fails). This approach tightly couples the core business logic of the Workforce with the presentation layer (console output).

This leads to several issues:

  • Poor Extensibility: Users who want to redirect logs to a file, a UI, or a remote monitoring service cannot do so without modifying the core Workforce code.
  • Inconsistent Logging: It mixes standard logger calls with print statements, making log management inconsistent.
  • Hardcoded Formatting: The use of colorama for console coloring is hardcoded within the core logic, whereas formatting should be a concern of the presentation/logging layer.

Solution

  • Define a log_info(self, event: LogEvent) method in the abstract base class WorkforceCallback.
  • Implement this method in the concrete implementation class WorkforceLogger. The implementation of WorkforceLogger.log_info checks the level field of the LogEvent (such as info, warning, error) and uses Python's logging module (logger.info, logger.warning, etc.) to output the log.
  • Color processing (such as using colorama) should also be done in WorkforceLogger or other callbacks specifically responsible for console output, not in the core Workforce class.

Alternatives

No response

Additional context

No response

coolbeevip avatar Oct 31 '25 15:10 coolbeevip

thanks @coolbeevip for opening this issue! Added to sprint 42

Wendong-Fan avatar Nov 10 '25 05:11 Wendong-Fan

I'd like to have a go at this issue. You can assign me

zshanhui avatar Nov 11 '25 06:11 zshanhui

I'd like to have a go at this issue. You can assign me

thanks @zshanhui assign to you

fengju0213 avatar Nov 11 '25 09:11 fengju0213

hey @zshanhui , thanks for taking this issue, any updates or any support we can provide for this feature implemenatation?

Wendong-Fan avatar Nov 24 '25 12:11 Wendong-Fan

hi @Wendong-Fan , i got stuck on a mypy and linting issue while running pre-commit run --all-files, but i think i got the hang of things now. i will open up another PR since the DRAFT one is out of date.

zshanhui avatar Nov 30 '25 14:11 zshanhui

hi @Wendong-Fan , i got stuck on a mypy and linting issue while running pre-commit run --all-files, but i think i got the hang of things now. i will open up another PR since the DRAFT one is out of date.

thanks !@zshanhui

fengju0213 avatar Dec 01 '25 04:12 fengju0213

i updated this issue with a PR @coolbeevip @Wendong-Fan

zshanhui avatar Dec 02 '25 16:12 zshanhui