[Feature Request] Refactor Workforce to Decouple Logging via Callbacks
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 classWorkforceCallback. - Implement this method in the concrete implementation class
WorkforceLogger. The implementation ofWorkforceLogger.log_infochecks thelevelfield of theLogEvent(such asinfo,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
WorkforceLoggeror other callbacks specifically responsible for console output, not in the coreWorkforceclass.
Alternatives
No response
Additional context
No response
thanks @coolbeevip for opening this issue! Added to sprint 42
I'd like to have a go at this issue. You can assign me
I'd like to have a go at this issue. You can assign me
thanks @zshanhui assign to you
hey @zshanhui , thanks for taking this issue, any updates or any support we can provide for this feature implemenatation?
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.
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
i updated this issue with a PR @coolbeevip @Wendong-Fan