It has been a while but I've worked out a better solution for this so here is my RFC, which I will use to write the functionality.
A LoggableTask which extends Task as described as follows.
A task can be run on either the command line or in the browser, therefore different types of output are required. In order to fulfil this purpose, a new task logging system can be introduced.
The task logging system should allow for one or more logging interfaces and should be configurable.
By default, when running the task in a web browser, a HttpLogger will be automatically added to the list of loggers. When running in the command line, a CommandLineLogger will be added.
The logging can also be configured on the command line by using parameters like so:
php framework/cli-script.php dev/tasks/MigrateSiteTreePages "logger=MyCustomLogger" "logger=FileLogger"
You can also configure the loggers in the browser like so:
/dev/tasks/MigrateSiteTreePages?logger[]=MyCustomLogger&logger[]=FileLogger
The logger will also be configurable in terms of verbosity. This can also be configured by passing parameters or by appending the URL with query string arguments.
When logging messages, the level of importance can be specified. The options for the levels are: high, normal, low
The verbosity levels are:
detailed, which displays all errors, warnings, messages (low, medium and high importance)
normal, which displays errors, warnings and messages with a medium or high importance
minimal, which displays errors, warnings and messages with a high importance
quiet, which displays errors and warnings
A new event system will be introduced, which will allow the task to raise events on various situations, such as:
task started
task message
task warning
task error
task finished
These events are raised either automatically by the LoggableTask, or programmed by the developer writing the task. For instance, task started, task finished, task warning and task error events will be raised automatically.
Each logger will be able to define what happens when each of these events is raised.
The LoggableTask will remove the default output, the task title, which SilverStripe adds, as it may not be desirable to output such information. This will be done by clearing the output buffer.
The LoggableTask, and accompanying classes, will be built as a module, and to use, your task should extend LoggableTask opposed to Task.
I welcome any questions or suggestions.