Skip to content
Bertie2011 edited this page Aug 29, 2021 · 1 revision

The CLIFramework\ActionLogger can help you to show and update statuses of long-running actions.

Create the action logger using an output stream, like the STDERR or STDOUT global constants.

Then call $logger->newAction($title, $desc, $status) to obtain a LogAction object. The status can be any string you want. Once you got a LogAction object, call $action->setStatus($status, $style) to update the previous line with the new status. Finish an action by calling $action->done(), after which you can create another action. Make sure to never have more than one running action.

To change the width of the output, call $action->setActionColumnWidth($width) on each action.

Example:

use CLIFramework\Logger\ActionLogger;
use CLIFramework\Formatter;

$logger = new ActionLogger(STDOUT, new Formatter);


foreach (['ProductSchema','OrderSchema', 'OrderItemSchema'] as $title) {
    $logAction = $logger->newAction($title, 'Update schema class files...');
    foreach (['checking', 'updating', 'pulling'] as $status) {
        $logAction->setStatus($status);
        sleep(1);
    }
    $logAction->done();
}