Skip to content

[Feature Request] Refactor Workforce to Decouple Logging via Callbacks #3351

@coolbeevip

Description

@coolbeevip

Required prerequisites

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions