From 8d24ff4d17128770ec4f70e33d69080268167c7c Mon Sep 17 00:00:00 2001 From: bergice Date: Wed, 17 Apr 2019 10:01:28 +1200 Subject: [PATCH 1/3] Add `PreformattedEchoHandler` cherry-picked from 4c3f3e6bea99b46b689e5b23d1bd1498a4ac696c --- src/Logging/PreformattedEchoHandler.php | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Logging/PreformattedEchoHandler.php diff --git a/src/Logging/PreformattedEchoHandler.php b/src/Logging/PreformattedEchoHandler.php new file mode 100644 index 00000000000..66336c24740 --- /dev/null +++ b/src/Logging/PreformattedEchoHandler.php @@ -0,0 +1,27 @@ +%s', htmlspecialchars($record['formatted'], ENT_QUOTES, 'UTF-8')); + } +} From 71964e054284aac8e20954dac0dc4c120f1b2366 Mon Sep 17 00:00:00 2001 From: bergice Date: Wed, 17 Apr 2019 17:30:57 +1200 Subject: [PATCH 2/3] Batch log messages for every 100 file. Also make logger work for stdout --- src/Dev/Tasks/MigrateFileTask.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Dev/Tasks/MigrateFileTask.php b/src/Dev/Tasks/MigrateFileTask.php index a7ca519f5e8..195b0fd4461 100644 --- a/src/Dev/Tasks/MigrateFileTask.php +++ b/src/Dev/Tasks/MigrateFileTask.php @@ -2,7 +2,13 @@ namespace SilverStripe\Dev\Tasks; +use Monolog\Handler\StreamHandler; +use Monolog\Logger; +use Psr\Log\LoggerInterface; use SilverStripe\AssetAdmin\Helper\ImageThumbnailHelper; +use SilverStripe\Control\Director; +use SilverStripe\Core\Injector\Injector; +use SilverStripe\Logging\PreformattedEchoHandler; use SilverStripe\ORM\DB; use SilverStripe\Assets\FileMigrationHelper; use SilverStripe\Dev\BuildTask; @@ -12,7 +18,6 @@ */ class MigrateFileTask extends BuildTask { - private static $segment = 'MigrateFileTask'; protected $title = 'Migrate File dataobjects from 3.x'; @@ -23,6 +28,8 @@ class MigrateFileTask extends BuildTask public function run($request) { + $this->addLogHandlers(); + if (!class_exists(FileMigrationHelper::class)) { DB::alteration_message("No file migration helper detected", "notice"); return; @@ -46,4 +53,22 @@ public function run($request) } ImageThumbnailHelper::singleton()->run(); } + + /** + * TODO Refactor this whole mess into Symfony Console on a TaskRunner level, + * with a thin wrapper to show coloured console output via a browser: + * https://github.com/silverstripe/silverstripe-framework/issues/5542 + * @throws \Exception + */ + protected function addLogHandlers() + { + if ($logger = Injector::inst()->get(LoggerInterface::class)) { + if (Director::is_cli()) { + $logger->pushHandler(new StreamHandler('php://stdout')); + $logger->pushHandler(new StreamHandler('php://stderr', Logger::WARNING)); + } else { + $logger->pushHandler(new PreformattedEchoHandler()); + } + } + } } From 3442530f7b558d3b1b68ae49aaca45ea15fa132e Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Thu, 18 Apr 2019 10:04:31 +1200 Subject: [PATCH 3/3] Update src/Logging/PreformattedEchoHandler.php Co-Authored-By: bergice --- src/Logging/PreformattedEchoHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Logging/PreformattedEchoHandler.php b/src/Logging/PreformattedEchoHandler.php index 66336c24740..b7a4d6821f8 100644 --- a/src/Logging/PreformattedEchoHandler.php +++ b/src/Logging/PreformattedEchoHandler.php @@ -12,7 +12,7 @@ * * See https://github.com/silverstripe/silverstripe-framework/issues/5542 * - * @experimental + * @internal */ class PreformattedEchoHandler extends AbstractProcessingHandler {