From 769b2ff3428455aeb70eb75e3cf1248eb0d2c1e8 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Sun, 5 Jul 2026 23:32:01 +0500 Subject: [PATCH] =?UTF-8?q?feat(logging):=20migrate=20remaining=20files=20?= =?UTF-8?q?to=20app=20channel=20=E2=80=94=20all=20Log::=20calls=20now=20us?= =?UTF-8?q?e=20domain=20channels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dashboard/Commands/FetchEmailNewsCommand.php | 4 ++-- .../Dashboard/Jobs/ProcessEmailNewsJob.php | 8 ++++---- .../Dashboard/Tasks/Files/CompressImageTask.php | 10 +++++----- .../Dashboard/Traits/MemoryAwareTrait.php | 4 ++-- .../WEB/Controllers/ParseEmailNewsController.php | 6 +++--- .../Actions/ClearStaticSearchCacheAction.php | 2 +- .../Search/Actions/SearchStaticFilesAction.php | 4 ++-- .../Search/Tasks/BuildStaticFileIndexTask.php | 6 +++--- .../Search/Tasks/GetStaticFileCategoriesTask.php | 6 +++--- app/Jobs/ImportApiDataPost.php | 14 +++++++------- app/Jobs/ImportUsers.php | 2 +- app/Jobs/RunBackup.php | 4 ++-- .../Filament/Domain/Posts/PostSliderService.php | 6 +++--- .../Filament/Services/StaticFileSearch.php | 10 +++++----- .../Vicon/DirectionStudy/AdmissionPlanService.php | 10 +++++----- .../Vicon/DirectionStudy/DirectionStudyService.php | 2 +- .../EducationalProgramService.php | 2 +- 17 files changed, 50 insertions(+), 50 deletions(-) diff --git a/app/Containers/Dashboard/Commands/FetchEmailNewsCommand.php b/app/Containers/Dashboard/Commands/FetchEmailNewsCommand.php index 6024021..274b4bf 100644 --- a/app/Containers/Dashboard/Commands/FetchEmailNewsCommand.php +++ b/app/Containers/Dashboard/Commands/FetchEmailNewsCommand.php @@ -66,7 +66,7 @@ class FetchEmailNewsCommand extends ConsoleCommand return $this->handleSync($fetchEmailNewsAction, $verbose); } catch (EmailFetchException $e) { $this->error('❌ Ошибка Email: ' . $e->getMessage()); - Log::error('[FetchEmailNewsCommand] EmailFetchException', [ + Log::channel('app')->error('EmailFetchException', [ 'code' => $e->getCode(), 'message' => $e->getMessage(), ]); @@ -76,7 +76,7 @@ class FetchEmailNewsCommand extends ConsoleCommand $this->error('❌ Критическая ошибка: ' . $e->getMessage()); $this->warn('Проверьте логи: storage/logs/laravel.log'); - Log::error('[FetchEmailNewsCommand] Critical Error', [ + Log::channel('app')->error('Critical Error', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); diff --git a/app/Containers/Dashboard/Jobs/ProcessEmailNewsJob.php b/app/Containers/Dashboard/Jobs/ProcessEmailNewsJob.php index 9c58b8e..7980127 100644 --- a/app/Containers/Dashboard/Jobs/ProcessEmailNewsJob.php +++ b/app/Containers/Dashboard/Jobs/ProcessEmailNewsJob.php @@ -57,7 +57,7 @@ class ProcessEmailNewsJob implements ShouldQueue */ public function handle(FetchEmailNewsAction $fetchEmailNewsAction): void { - Log::info('[ProcessEmailNewsJob] Начало обработки job', [ + Log::channel('app')->info('Начало обработки job', [ 'job_id' => $this->job?->getJobId() ?? 'unknown', 'attempt' => $this->attempts(), 'memory_limit' => ini_get('memory_limit'), @@ -66,7 +66,7 @@ class ProcessEmailNewsJob implements ShouldQueue // Выполняем обработку — если выбросит исключение, Laravel автоматически повторит job $result = $fetchEmailNewsAction->run(); - Log::info('[ProcessEmailNewsJob] Обработка завершена успешно', [ + Log::channel('app')->info('Обработка завершена успешно', [ 'job_id' => $this->job?->getJobId() ?? 'unknown', 'processed_emails' => $result['processed_emails'], 'created_posts' => $result['created_posts'], @@ -79,7 +79,7 @@ class ProcessEmailNewsJob implements ShouldQueue // Если были ошибки, логируем их как warning if (!empty($result['errors'])) { foreach ($result['errors'] as $error) { - Log::warning('[ProcessEmailNewsJob] Ошибка обработки письма', [ + Log::channel('app')->warning('Ошибка обработки письма', [ 'subject' => $error['email_subject'] ?? 'unknown', 'error' => $error['error'], ]); @@ -95,7 +95,7 @@ class ProcessEmailNewsJob implements ShouldQueue */ public function failed(\Throwable $exception): void { - Log::critical('[ProcessEmailNewsJob] Job окончательно провален', [ + Log::channel('app')->critical('Job окончательно провален', [ 'total_attempts' => $this->tries, 'error' => $exception->getMessage(), ]); diff --git a/app/Containers/Dashboard/Tasks/Files/CompressImageTask.php b/app/Containers/Dashboard/Tasks/Files/CompressImageTask.php index 9f7f1b1..8177f1f 100644 --- a/app/Containers/Dashboard/Tasks/Files/CompressImageTask.php +++ b/app/Containers/Dashboard/Tasks/Files/CompressImageTask.php @@ -43,7 +43,7 @@ class CompressImageTask { $extension = strtolower($file->getClientOriginalExtension()); - Log::info('[CompressImageTask] Начало обработки изображения', [ + Log::channel('app')->info('Начало обработки изображения', [ 'file' => $file->getClientOriginalName(), 'extension' => $extension, 'size' => $this->formatFileSize($file->getSize()), @@ -52,7 +52,7 @@ class CompressImageTask // Если файл уже меньше порога и это WebP - пропускаем сжатие if ($file->getSize() <= self::SIZE_THRESHOLD && $extension === 'webp') { - Log::info('[CompressImageTask] Файл уже оптимизирован, пропускаем', [ + Log::channel('app')->info('Файл уже оптимизирован, пропускаем', [ 'file' => $file->getClientOriginalName(), ]); @@ -71,7 +71,7 @@ class CompressImageTask $originalWidth = $img->width(); $originalHeight = $img->height(); - Log::info('[CompressImageTask] Исходные размеры', [ + Log::channel('app')->info('Исходные размеры', [ 'width' => $originalWidth, 'height' => $originalHeight, ]); @@ -83,7 +83,7 @@ class CompressImageTask $constraint->upsize(); }); - Log::info('[CompressImageTask] Изображение ресайзнуто', [ + Log::channel('app')->info('Изображение ресайзнуто', [ 'new_width' => $img->width(), 'new_height' => $img->height(), ]); @@ -99,7 +99,7 @@ class CompressImageTask $newSize = filesize($tempPath); - Log::info('[CompressImageTask] Сжатие завершено', [ + Log::channel('app')->info('Сжатие завершено', [ 'original_size' => $this->formatFileSize($file->getSize()), 'compressed_size' => $this->formatFileSize($newSize), 'compression_ratio' => round((1 - $newSize / $file->getSize()) * 100, 2) . '%', diff --git a/app/Containers/Dashboard/Traits/MemoryAwareTrait.php b/app/Containers/Dashboard/Traits/MemoryAwareTrait.php index 32ea9ad..d3fab21 100644 --- a/app/Containers/Dashboard/Traits/MemoryAwareTrait.php +++ b/app/Containers/Dashboard/Traits/MemoryAwareTrait.php @@ -47,7 +47,7 @@ trait MemoryAwareTrait // Логируем только если превышен порог if ($currentMemory > $this->memoryLogThreshold) { - Log::info('[MemoryMonitor] Использование памяти', [ + Log::channel('app')->info('Использование памяти', [ 'context' => $context, 'current' => round($currentMemory / 1024 / 1024, 2) . 'MB', 'peak' => round($peakMemory / 1024 / 1024, 2) . 'MB', @@ -75,7 +75,7 @@ trait MemoryAwareTrait $memoryAfter = round(memory_get_usage(true) / 1024 / 1024, 2); $freed = round(($memoryBefore - $memoryAfter), 2); - Log::info('[MemoryMonitor] Сборка мусора выполнена', [ + Log::channel('app')->info('Сборка мусора выполнена', [ 'memory_before' => $memoryBefore . 'MB', 'memory_after' => $memoryAfter . 'MB', 'freed' => $freed . 'MB', diff --git a/app/Containers/Dashboard/UI/WEB/Controllers/ParseEmailNewsController.php b/app/Containers/Dashboard/UI/WEB/Controllers/ParseEmailNewsController.php index f3da0fb..7c7b208 100644 --- a/app/Containers/Dashboard/UI/WEB/Controllers/ParseEmailNewsController.php +++ b/app/Containers/Dashboard/UI/WEB/Controllers/ParseEmailNewsController.php @@ -18,7 +18,7 @@ class ParseEmailNewsController extends Controller public function __invoke(Request $request): RedirectResponse { try { - Log::info('[ParseEmailNewsController] Принудительный запуск парсинга email'); + Log::channel('app')->info('Принудительный запуск парсинга email'); $result = $this->fetchEmailNewsAction->run(); @@ -38,13 +38,13 @@ class ParseEmailNewsController extends Controller "Обработано писем: {$result['processed_emails']}, но новостей не создано" ); } catch (EmailFetchException $e) { - Log::error('[ParseEmailNewsController] EmailFetchException', [ + Log::channel('app')->error('EmailFetchException', [ 'error' => $e->getMessage(), ]); return redirect()->back()->with('error', $e->getMessage()); } catch (\Exception $e) { - Log::error('[ParseEmailNewsController] Критическая ошибка', [ + Log::channel('app')->error('Критическая ошибка', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); diff --git a/app/Containers/Search/Actions/ClearStaticSearchCacheAction.php b/app/Containers/Search/Actions/ClearStaticSearchCacheAction.php index c699b14..a7ce438 100755 --- a/app/Containers/Search/Actions/ClearStaticSearchCacheAction.php +++ b/app/Containers/Search/Actions/ClearStaticSearchCacheAction.php @@ -15,7 +15,7 @@ class ClearStaticSearchCacheAction Cache::forget(self::CACHE_KEY); return true; } catch (\Exception $e) { - Log::error('Cache clear error: ' . $e->getMessage()); + Log::channel('app')->error('Cache clear error: ' . $e->getMessage()); return false; } } diff --git a/app/Containers/Search/Actions/SearchStaticFilesAction.php b/app/Containers/Search/Actions/SearchStaticFilesAction.php index 8e8a867..aae2c8b 100755 --- a/app/Containers/Search/Actions/SearchStaticFilesAction.php +++ b/app/Containers/Search/Actions/SearchStaticFilesAction.php @@ -47,7 +47,7 @@ class SearchStaticFilesAction return app(PaginateSearchResultsTask::class)->run($results, $page, self::PER_PAGE, $categories); } catch (\Exception $e) { - Log::error('Search error: ' . $e->getMessage()); + Log::channel('app')->error('Search error: ' . $e->getMessage()); return [ 'data' => [], 'meta' => [ @@ -77,7 +77,7 @@ class SearchStaticFilesAction return null; } catch (\Exception $e) { - Log::error('Failed to get H1: ' . $e->getMessage()); + Log::channel('app')->error('Failed to get H1: ' . $e->getMessage()); return null; } } diff --git a/app/Containers/Search/Tasks/BuildStaticFileIndexTask.php b/app/Containers/Search/Tasks/BuildStaticFileIndexTask.php index d8e7e05..fcdb760 100755 --- a/app/Containers/Search/Tasks/BuildStaticFileIndexTask.php +++ b/app/Containers/Search/Tasks/BuildStaticFileIndexTask.php @@ -24,7 +24,7 @@ class BuildStaticFileIndexTask $directory = public_path(self::FILES_DIR); if (!is_dir($directory)) { - Log::error("Directory not found: {$directory}"); + Log::channel('app')->error("Directory not found: {$directory}"); return []; } @@ -51,7 +51,7 @@ class BuildStaticFileIndexTask return $index; } catch (\Exception $e) { - Log::error('Index creation error: ' . $e->getMessage()); + Log::channel('app')->error('Index creation error: ' . $e->getMessage()); return []; } }); @@ -80,7 +80,7 @@ class BuildStaticFileIndexTask return null; } catch (\Exception $e) { - Log::error('Failed to get H1: ' . $e->getMessage()); + Log::channel('app')->error('Failed to get H1: ' . $e->getMessage()); return null; } } diff --git a/app/Containers/Search/Tasks/GetStaticFileCategoriesTask.php b/app/Containers/Search/Tasks/GetStaticFileCategoriesTask.php index 6524249..f88c9d2 100755 --- a/app/Containers/Search/Tasks/GetStaticFileCategoriesTask.php +++ b/app/Containers/Search/Tasks/GetStaticFileCategoriesTask.php @@ -14,7 +14,7 @@ class GetStaticFileCategoriesTask try { $file = public_path(self::FILES_DIR . '/' . 'index.html'); if (!file_exists($file)) { - Log::error("Category index file not found: {$file}"); + Log::channel('app')->error("Category index file not found: {$file}"); return []; } @@ -24,7 +24,7 @@ class GetStaticFileCategoriesTask $dropdownMenu = $document->first('ul.dropdown-menu'); if ($dropdownMenu === null) { - Log::warning("Dropdown menu not found in category index file: {$file}"); + Log::channel('app')->warning("Dropdown menu not found in category index file: {$file}"); return []; } @@ -38,7 +38,7 @@ class GetStaticFileCategoriesTask return $categories; } catch (\Exception $e) { - Log::error('Error extracting categories: ' . $e->getMessage()); + Log::channel('app')->error('Error extracting categories: ' . $e->getMessage()); return []; } } diff --git a/app/Jobs/ImportApiDataPost.php b/app/Jobs/ImportApiDataPost.php index 4d95c4c..76c828c 100755 --- a/app/Jobs/ImportApiDataPost.php +++ b/app/Jobs/ImportApiDataPost.php @@ -34,7 +34,7 @@ class ImportApiDataPost implements ShouldQueue // Получаем первую страницу данных $response = Http::get(config('TRANSFER_PROXY_URL') . '/api/posts')->object(); $last_page = $response->last_page; - Log::info('Last page: ' . $last_page); + Log::channel('app')->info('Last page: ' . $last_page); // Проходим по всем страницам for ($page = 1; $page <= $last_page; $page++) { @@ -43,7 +43,7 @@ class ImportApiDataPost implements ShouldQueue // Обрабатываем каждую запись foreach ($results as $post) { - Log::info('Processing post ID: ' . $post->ID); + Log::channel('app')->info('Processing post ID: ' . $post->ID); try { // Получаем массив изображений @@ -52,7 +52,7 @@ class ImportApiDataPost implements ShouldQueue // Проверяем, есть ли изображения if (empty($images)) { - Log::warning('No images found for post ID: ' . $post->ID); + Log::channel('app')->warning('No images found for post ID: ' . $post->ID); } else { // Проходимся по массиву изображений foreach ($images as $image) { @@ -60,13 +60,13 @@ class ImportApiDataPost implements ShouldQueue if (isset($image->SUBDIR) && isset($image->FILE_NAME)) { $imagePaths[] = 'upload/' . $image->SUBDIR . '/' . $image->FILE_NAME; } else { - Log::warning('Image data is incomplete for post ID: ' . $post->ID); + Log::channel('app')->warning('Image data is incomplete for post ID: ' . $post->ID); } } } // Логируем пути к изображениям для отладки - Log::info('Image paths for post ID ' . $post->ID . ': ' . json_encode($imagePaths)); + Log::channel('app')->debug('Image paths for post', ['post_id' => $post->ID, 'paths' => $imagePaths]); // Обработка контента поста $content = strip_tags($post->DETAIL_TEXT, ''); @@ -110,12 +110,12 @@ class ImportApiDataPost implements ShouldQueue $this->createSeo($createdPost); } catch (\Exception $e) { - Log::error('Error importing post ID: ' . $post->ID . ' - ' . $e->getMessage()); + Log::channel('app')->error('Error importing post ID: ' . $post->ID . ' - ' . $e->getMessage()); } } } } catch (\Exception $e) { - Log::error('Error fetching posts: ' . $e->getMessage()); + Log::channel('app')->error('Error fetching posts: ' . $e->getMessage()); } } diff --git a/app/Jobs/ImportUsers.php b/app/Jobs/ImportUsers.php index a1df6d4..8073160 100755 --- a/app/Jobs/ImportUsers.php +++ b/app/Jobs/ImportUsers.php @@ -79,7 +79,7 @@ class ImportUsers implements ShouldQueue } } } catch (\Exception $e) { - Log::error('Error fetching posts: ' . $e->getMessage()); + Log::channel('app')->error('Error fetching posts: ' . $e->getMessage()); } } } diff --git a/app/Jobs/RunBackup.php b/app/Jobs/RunBackup.php index fa8f693..ff60f67 100755 --- a/app/Jobs/RunBackup.php +++ b/app/Jobs/RunBackup.php @@ -32,7 +32,7 @@ class RunBackup implements ShouldQueue ]); // Логируем вывод - Log::info('Backup command output: ' . Artisan::output()); - Log::error('Backup command exit code: ' . $exitCode); + Log::channel('app')->info('Backup command output: ' . Artisan::output()); + Log::channel('app')->error('Backup command exit code: ' . $exitCode); } } diff --git a/app/Services/Filament/Domain/Posts/PostSliderService.php b/app/Services/Filament/Domain/Posts/PostSliderService.php index 6e3bd3f..787400c 100755 --- a/app/Services/Filament/Domain/Posts/PostSliderService.php +++ b/app/Services/Filament/Domain/Posts/PostSliderService.php @@ -38,9 +38,9 @@ class PostSliderService ]); $post->slide()->save($slide); - Log::info('Slide created successfully', ['postTitle' => $this->post->title]); + Log::channel('app')->info('Slide created successfully', ['postTitle' => $this->post->title]); } catch (\Exception $e) { - Log::error('Failed to create slide', [ + Log::channel('app')->error('Failed to create slide', [ 'postTitle' => $this->post->title, 'error' => $e->getMessage(), ]); @@ -71,7 +71,7 @@ class PostSliderService ]); } catch (\Exception $e) { - Log::error('Failed to update MainSlider', [ + Log::channel('app')->error('Failed to update MainSlider', [ 'postTitle' => $this->post->title, 'error' => $e->getMessage(), ]); diff --git a/app/Services/Filament/Services/StaticFileSearch.php b/app/Services/Filament/Services/StaticFileSearch.php index 0b0cdad..afd2d71 100755 --- a/app/Services/Filament/Services/StaticFileSearch.php +++ b/app/Services/Filament/Services/StaticFileSearch.php @@ -61,7 +61,7 @@ class StaticFileSearch return $this->paginateResults($results, $page, $categories); } catch (\Exception $e) { - Log::error('Search error: ' . $e->getMessage()); + Log::channel('app')->error('Search error: ' . $e->getMessage()); return [ 'data' => [], 'meta' => [ @@ -103,7 +103,7 @@ class StaticFileSearch $directory = public_path(self::FILES_DIR); if (!is_dir($directory)) { - Log::error("Directory not found: {$directory}"); + Log::channel('app')->error("Directory not found: {$directory}"); return []; } @@ -130,7 +130,7 @@ class StaticFileSearch return $index; } catch (\Exception $e) { - Log::error('Index creation error: ' . $e->getMessage()); + Log::channel('app')->error('Index creation error: ' . $e->getMessage()); return []; } }); @@ -181,7 +181,7 @@ class StaticFileSearch Cache::forget(self::CACHE_KEY); return true; } catch (\Exception $e) { - Log::error('Cache clear error: ' . $e->getMessage()); + Log::channel('app')->error('Cache clear error: ' . $e->getMessage()); return false; } } @@ -212,7 +212,7 @@ class StaticFileSearch return null; } catch (\Exception $e) { - Log::error('Failed to get H1: ' . $e->getMessage()); + Log::channel('app')->error('Failed to get H1: ' . $e->getMessage()); return null; } } diff --git a/app/Services/Vicon/DirectionStudy/AdmissionPlanService.php b/app/Services/Vicon/DirectionStudy/AdmissionPlanService.php index 629073f..2d20216 100755 --- a/app/Services/Vicon/DirectionStudy/AdmissionPlanService.php +++ b/app/Services/Vicon/DirectionStudy/AdmissionPlanService.php @@ -31,7 +31,7 @@ class AdmissionPlanService config('services.vicon.token') ); if (!is_array($response)) { - Log::warning('Unexpected response type in getCampaigns', [ + Log::channel('app')->warning('Unexpected response type in getCampaigns', [ 'type' => gettype($response), 'response' => $response ]); @@ -39,7 +39,7 @@ class AdmissionPlanService return $response; } catch (\Exception $e) { - Log::error('API call failed in getCampaigns', [ + Log::channel('app')->error('API call failed in getCampaigns', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); @@ -56,7 +56,7 @@ class AdmissionPlanService ); if (!is_object($response)) { - Log::warning('Unexpected response type in getAdmissionPlans', [ + Log::channel('app')->warning('Unexpected response type in getAdmissionPlans', [ 'expected' => 'object', 'actual' => gettype($response), 'campaign_levels_code' => $campaign_levels_code, @@ -68,7 +68,7 @@ class AdmissionPlanService return $response; } catch (\Exception $e) { - Log::error('API call failed in getAdmissionPlans', [ + Log::channel('app')->error('API call failed in getAdmissionPlans', [ 'error' => $e->getMessage(), 'campaign_levels_code' => $campaign_levels_code, 'trace' => $e->getTraceAsString() @@ -137,7 +137,7 @@ class AdmissionPlanService return $data; } catch (\Exception $e) { - Log::error('Ошибка при вызове API: ' . $e->getMessage()); + Log::channel('app')->error('Ошибка при вызове API: ' . $e->getMessage()); throw $e; // Перебрасываем исключение } } diff --git a/app/Services/Vicon/DirectionStudy/DirectionStudyService.php b/app/Services/Vicon/DirectionStudy/DirectionStudyService.php index c8143ab..67d15d2 100755 --- a/app/Services/Vicon/DirectionStudy/DirectionStudyService.php +++ b/app/Services/Vicon/DirectionStudy/DirectionStudyService.php @@ -81,7 +81,7 @@ class DirectionStudyService return $data; } catch (\Exception $e) { - Log::error('Ошибка при вызове API: ' . $e->getMessage()); + Log::channel('app')->error('API call failed', ['error' => $e->getMessage()]); throw $e; // Перебрасываем исключение } } diff --git a/app/Services/Vicon/EducationalProgram/EducationalProgramService.php b/app/Services/Vicon/EducationalProgram/EducationalProgramService.php index fcb7b86..341d8ad 100755 --- a/app/Services/Vicon/EducationalProgram/EducationalProgramService.php +++ b/app/Services/Vicon/EducationalProgram/EducationalProgramService.php @@ -50,7 +50,7 @@ class EducationalProgramService return $data; } catch (\Exception $e) { - Log::error('Ошибка при вызове API: ' . $e->getMessage()); + Log::channel('app')->error('API call failed', ['error' => $e->getMessage()]); throw $e; // Перебрасываем исключение } }