trash-panda/progress-bar-log

组件,用于同时显示进度条和最后X条日志

1.5 2020-07-15 13:12 UTC

This package is auto-updated.

Last update: 2024-09-19 15:37:44 UTC


README

在CLI中同时显示进度条和部分日志!

Preview

点击上面的图片查看实际效果。

安装

$ composer require trash-panda/progress-bar-log

用例

最初我想为长时间运行的导入/导出工作制作这个。能够看到最近日志条目的子集,同时仍然可以看到进度和内存使用情况,而无需滚动终端。我想这也许对其他人也有用。

用法

<?php

use Psr\Log\LogLevel;
use TrashPanda\ProgressBarLog\ProgressBarLog;

require_once __DIR__ . '/vendor/autoload.php';

//The first parameter is the number of log lines to be displayed. The newest entries will be displayed - like a tail.
//The second parameter is the maximum number of steps for the progress bar
$progressLog = new ProgressBarLog(6, 10);
$progressLog->start();

//advance the progress bar by one
$progressLog->advance();

//Add a log line - the first parameter is a psr/log severity constant
//you can pass whatever you want there - but if it is a psr/log constant then the severity is colored accordingly
$progressLog->addLog(LogLevel::CRITICAL, 'Some mission critical error');

查看example.php获取工作脚本示例

git clone git@github.com:AydinHassan/progress-bar-log.git
cd progress-bar-log
php example.php

自定义进度条

底层的进度条是\Symfony\Component\Console\Helper\ProgressBar的一个实例。

您可以通过getProgressBar()获取实例来修改进度条的设置

<?php

use TrashPanda\ProgressBarLog\ProgressBarLog;

require_once __DIR__ . '/vendor/autoload.php';

$progressLog = new ProgressBarLog(6, 10);
$progressLog->getProgressBar()->setFormat('normal');
$progressLog->getProgressBar()->setBarWidth(50);
$progressLog->start();

运行单元测试

$ composer test