diff --git a/app/Classes/General/Abstracts/AbstractControllerLogic.php b/app/Classes/General/Abstracts/AbstractControllerLogic.php index f26e2ad0..de7c2ae6 100644 --- a/app/Classes/General/Abstracts/AbstractControllerLogic.php +++ b/app/Classes/General/Abstracts/AbstractControllerLogic.php @@ -18,6 +18,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use App\Classes\Exceptions\JobResourceNotFoundException; +use App\Classes\General\LogHelper; abstract class AbstractControllerLogic { @@ -69,7 +70,7 @@ abstract class AbstractControllerLogic } catch (ErrorException|GeneralExceptions $exception){ if ($exception instanceof JobResourceNotFoundException) { - Log::channel('vue_polling')->info(sprintf( + LogHelper::channel('vue_polling')->info(sprintf( "Uncaught exception '%s' with message '%s' in %s:%d", get_class($exception), $exception->getMessage(), diff --git a/app/Logging/CloudWatchLoggerFactory.php b/app/Logging/CloudWatchLoggerFactory.php new file mode 100644 index 00000000..14c5da6e --- /dev/null +++ b/app/Logging/CloudWatchLoggerFactory.php @@ -0,0 +1,46 @@ +setFormatter(new JsonFormatter()); + // Create a log channel + $logger = new Logger($name); + // Set handler + $logger->pushHandler($handler); + //$logger->pushProcessor(new CompanyLogProcessor()); //Use this if you want to adjust the JSON output using a log processor + return $logger; + } +} diff --git a/config/logging.php b/config/logging.php index d4894384..0c9a6ec1 100644 --- a/config/logging.php +++ b/config/logging.php @@ -99,15 +99,18 @@ return [ 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], + + 'guzzleShippingPortal' => [ + 'driver' => 'errorlog', + 'level' => 'debug', + ], + + //Custom Log Channels - Starts 'regenerateInvoice' => [ 'driver' => 'single', 'path' => storage_path('logs/regenerateInvoice.log'), 'level' => 'info', ], - 'guzzleShippingPortal' => [ - 'driver' => 'errorlog', - 'level' => 'debug', - ], 'vue_polling' => [ 'driver' => 'single', @@ -120,7 +123,63 @@ return [ 'path' => storage_path('logs/laravel_perfex_crm.log'), 'level' => 'info', ], + //Custom Log Channels - Ends + //Custom Log Channels - For Laravel Vapor AWS - Starts + 'regenerateInvoice_vapor' => [ + 'driver' => 'custom', + 'via' => \App\Logging\CloudWatchLoggerFactory::class, + 'formatter' => Monolog\Formatter\JsonFormatter::class, + 'cloudwatch_stream_name' => 'regenerateInvoice_vapor', + 'sdk' => [ + 'region' => env('AWS_MY_REGION'), + 'version' => 'latest', + 'credentials' => [ + 'key' => env('AWS_CW_ACCESS'), + 'secret' => env('AWS_CW_SECRET') + ] + ], + 'retention' => 31, + 'level' => 'debug', + 'groupNamePrefix' => env('CLOUDWATCH_LOGGROUP_PREFIX'), + ], + + 'vue_polling_vapor' => [ + 'driver' => 'custom', + 'via' => \App\Logging\CloudWatchLoggerFactory::class, + 'formatter' => Monolog\Formatter\JsonFormatter::class, + 'cloudwatch_stream_name' => 'vue_polling_vapor', + 'sdk' => [ + 'region' => env('AWS_MY_REGION'), + 'version' => 'latest', + 'credentials' => [ + 'key' => env('AWS_CW_ACCESS'), + 'secret' => env('AWS_CW_SECRET') + ] + ], + 'retention' => 31, + 'level' => 'debug', + 'groupNamePrefix' => env('CLOUDWATCH_LOGGROUP_PREFIX'), + ], + + 'perfex_crm_vapor' => [ + 'driver' => 'custom', + 'via' => \App\Logging\CloudWatchLoggerFactory::class, + 'formatter' => Monolog\Formatter\JsonFormatter::class, + 'cloudwatch_stream_name' => 'perfex_crm_vapor', + 'sdk' => [ + 'region' => env('AWS_MY_REGION'), + 'version' => 'latest', + 'credentials' => [ + 'key' => env('AWS_CW_ACCESS'), + 'secret' => env('AWS_CW_SECRET') + ] + ], + 'retention' => 31, + 'level' => 'debug', + 'groupNamePrefix' => env('CLOUDWATCH_LOGGROUP_PREFIX'), + ], + //Custom Log Channels - For Laravel Vapor AWS - Ends ], ]; diff --git a/routes/web.php b/routes/web.php index 188dde5e..69b1b76d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ chunk(100, function ($bookings) use (&$processed_invoice) { foreach ($bookings as $booking) { - Log::channel('regenerateInvoice')->info('Counter ' . $processed_invoice); + LogHelper::channel('regenerateInvoice')->info('Counter ' . $processed_invoice); dump('Counter ' . $processed_invoice); $processed_invoice += 1; @@ -703,18 +704,18 @@ Route::get('/invoice/fix', function(){ $existing_invoice_bill_no = Transaction::withTrashed()->where('bill_no', $bill_no)->first(); if ($existing_invoice_bill_no) { - Log::channel('regenerateInvoice')->info('Delete existing bill_no'); - Log::channel('regenerateInvoice')->info(json_encode($existing_invoice_bill_no)); + LogHelper::channel('regenerateInvoice')->info('Delete existing bill_no'); + LogHelper::channel('regenerateInvoice')->info(json_encode($existing_invoice_bill_no)); $existing_invoice_bill_no->forceDelete(); } (App()->make(CreateInvoiceTransactionWithInvoiceNoProcessor::class))->execute($booking, $bill_no); dump('regenerated invoice. Booking Marking - ' . $booking->marking . '. Bill_no - ' . $bill_no . '. Old bill_no - ' . $deletedInvoice->bill_no); - Log::channel('regenerateInvoice')->info('regenerated invoice. Booking Marking - ' . $booking->marking . '. Bill_no - ' . $bill_no . '. Old bill_no - ' . $deletedInvoice->bill_no); + LogHelper::channel('regenerateInvoice')->info('regenerated invoice. Booking Marking - ' . $booking->marking . '. Bill_no - ' . $bill_no . '. Old bill_no - ' . $deletedInvoice->bill_no); } else { (App()->make(CreateInvoiceTransactionProcessor::class))->execute($booking); dump('regenerated new invoice. Booking Marking - ' . $booking->marking); - Log::channel('regenerateInvoice')->info('regenerated new invoice. Booking Marking - ' . $booking->marking); + LogHelper::channel('regenerateInvoice')->info('regenerated new invoice. Booking Marking - ' . $booking->marking); } } } @@ -968,7 +969,7 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking, ->chunk(100, function ($bookings) use (&$processed_invoice) { foreach ($bookings as $booking) { - Log::channel('regenerateInvoice')->info('Counter ' . $processed_invoice); + LogHelper::channel('regenerateInvoice')->info('Counter ' . $processed_invoice); dump('Counter ' . $processed_invoice); dump('Marking ' . $booking->marking); $processed_invoice += 1; @@ -1006,7 +1007,7 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking, (App()->make(CreateInvoiceTransactionWithInvoiceNoProcessor::class))->execute($booking, $firstBillNo); dump('regenerated invoice. Booking Marking - ' . $booking->marking . '. Bill_no - ' . $firstBillNo . '. Old bill_no - ' . $currentInvoice->bill_no); - Log::channel('regenerateInvoice')->info('regenerated invoice. Booking Marking - ' . $booking->marking . '. Bill_no - ' . $firstBillNo . '. Old bill_no - ' . $currentInvoice->bill_no); + LogHelper::channel('regenerateInvoice')->info('regenerated invoice. Booking Marking - ' . $booking->marking . '. Bill_no - ' . $firstBillNo . '. Old bill_no - ' . $currentInvoice->bill_no); } } );