From 205c5f57b1de12f8aa8f381d40098e62a75f2683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Sun, 1 Oct 2017 17:26:03 +0200 Subject: [PATCH 1/4] Implement Custom Log File #2 --- src/DeleteOldSoftDeletes.php | 7 +++++++ src/config/quicksand.php | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/DeleteOldSoftDeletes.php b/src/DeleteOldSoftDeletes.php index 1bf0f2e..815334e 100644 --- a/src/DeleteOldSoftDeletes.php +++ b/src/DeleteOldSoftDeletes.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; +use Monolog\Logger; class DeleteOldSoftDeletes extends Command { @@ -75,6 +76,12 @@ private function logAffectedRows(Collection $deletedRows) if (! $this->config->get('quicksand.log', false) || empty($preparedRows)) { return; } + /** + * @var \Illuminate\Contracts\Logging\Log $monolog + */ + if (! $this->config->get('quicksand.custom_log_file', false)) { + Log::useFiles($this->config->get('quicksand.custom_log_file')); + } Log::info(sprintf( '%s force deleted these number of rows: %s', diff --git a/src/config/quicksand.php b/src/config/quicksand.php index b90502d..ffe0d88 100644 --- a/src/config/quicksand.php +++ b/src/config/quicksand.php @@ -7,6 +7,10 @@ // Whether to log the number of soft deleted records per model 'log' => false, + // If you log the soft deleted records per model, this is the path where it will be stored + // false if you want the default laravel log file + 'custom_log_file' => false, + // List of models to run Quicksand on 'models' => [ // \App\Example::class, From 9a52dfd4ac968ba96dac5c6319b87f9576cc4e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Sun, 1 Oct 2017 17:29:26 +0200 Subject: [PATCH 2/4] Remove unnecessary docblock --- src/DeleteOldSoftDeletes.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/DeleteOldSoftDeletes.php b/src/DeleteOldSoftDeletes.php index 815334e..20a5be4 100644 --- a/src/DeleteOldSoftDeletes.php +++ b/src/DeleteOldSoftDeletes.php @@ -76,9 +76,7 @@ private function logAffectedRows(Collection $deletedRows) if (! $this->config->get('quicksand.log', false) || empty($preparedRows)) { return; } - /** - * @var \Illuminate\Contracts\Logging\Log $monolog - */ + if (! $this->config->get('quicksand.custom_log_file', false)) { Log::useFiles($this->config->get('quicksand.custom_log_file')); } From 4a36f7c69592d08f887da11cc674fd7c9d4996ee Mon Sep 17 00:00:00 2001 From: LK Development Date: Tue, 3 Oct 2017 01:51:09 +0200 Subject: [PATCH 3/4] Fix suggestions from Matt - Happy Birthday :) --- src/DeleteOldSoftDeletes.php | 3 +-- src/config/quicksand.php | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DeleteOldSoftDeletes.php b/src/DeleteOldSoftDeletes.php index 20a5be4..f320396 100644 --- a/src/DeleteOldSoftDeletes.php +++ b/src/DeleteOldSoftDeletes.php @@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; -use Monolog\Logger; class DeleteOldSoftDeletes extends Command { @@ -77,7 +76,7 @@ private function logAffectedRows(Collection $deletedRows) return; } - if (! $this->config->get('quicksand.custom_log_file', false)) { + if (!! $this->config->get('quicksand.custom_log_file', false)) { Log::useFiles($this->config->get('quicksand.custom_log_file')); } diff --git a/src/config/quicksand.php b/src/config/quicksand.php index ffe0d88..1868247 100644 --- a/src/config/quicksand.php +++ b/src/config/quicksand.php @@ -9,6 +9,7 @@ // If you log the soft deleted records per model, this is the path where it will be stored // false if you want the default laravel log file + // Sample Path: __DIR__.'/path/to/storage/from/log.file 'custom_log_file' => false, // List of models to run Quicksand on From f9c307eb44333e53e9fbd38a8886cb8ee4b7713d Mon Sep 17 00:00:00 2001 From: LK Development Date: Tue, 3 Oct 2017 16:58:35 +0200 Subject: [PATCH 4/4] Make the Log write to only one file and restore it after the log. --- src/DeleteOldSoftDeletes.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/DeleteOldSoftDeletes.php b/src/DeleteOldSoftDeletes.php index f320396..42b1b0d 100644 --- a/src/DeleteOldSoftDeletes.php +++ b/src/DeleteOldSoftDeletes.php @@ -77,7 +77,10 @@ private function logAffectedRows(Collection $deletedRows) } if (!! $this->config->get('quicksand.custom_log_file', false)) { + $logHandlers = Log::getMonolog()->getHandlers(); + Log::getMonolog()->setHandlers([]); Log::useFiles($this->config->get('quicksand.custom_log_file')); + } Log::info(sprintf( @@ -85,6 +88,10 @@ private function logAffectedRows(Collection $deletedRows) get_class($this), print_r($preparedRows, true) )); + + if (!! $this->config->get('quicksand.custom_log_file', false)) { + Log::getMonolog()->setHandlers($logHandlers); + } } private function prepareForLogging($rawDeletedRows)