diff --git a/app/Helpers/Generic.php b/app/Helpers/Generic.php index 651d040349..33c5b4ba80 100644 --- a/app/Helpers/Generic.php +++ b/app/Helpers/Generic.php @@ -44,3 +44,29 @@ function nlog($output, $context = []): void $output = null; $context = null; } + + +function nrlog($output, $context = []): void +{ + if (! config('ninja.expanded_logging')) { + return; + } + + if (gettype($output) == 'object') { + $output = print_r($output, 1); + } + + // $trace = debug_backtrace(); + + if (Ninja::isHosted()) { + try { + info($output); + } catch (\Exception $e) { + } + } else { + \Illuminate\Support\Facades\Log::channel('invoiceninja-reminders')->info($output, $context); + } + + $output = null; + $context = null; +} diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index ac3f6e45dd..64c0ebce92 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -56,7 +56,7 @@ class ReminderJob implements ShouldQueue Auth::logout(); if (! config('ninja.db.multi_db_enabled')) { - nlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s')); + nrlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s')); Invoice::query() ->where('is_deleted', 0) @@ -84,7 +84,7 @@ class ReminderJob implements ShouldQueue foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); - nlog("Sending invoice reminders on db {$db} ".now()->format('Y-m-d h:i:s')); + nrlog("Sending invoice reminders on db {$db} ".now()->format('Y-m-d h:i:s')); Invoice::query() ->where('is_deleted', 0) @@ -121,12 +121,12 @@ class ReminderJob implements ShouldQueue if ($invoice->isPayable()) { //Attempts to prevent duplicates from sending if ($invoice->reminder_last_sent && Carbon::parse($invoice->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())) { - nlog("caught a duplicate reminder for invoice {$invoice->number}"); + nrlog("caught a duplicate reminder for invoice {$invoice->number}"); return; } $reminder_template = $invoice->calculateTemplate('invoice'); - nlog("reminder template = {$reminder_template}"); + nrlog("reminder template = {$reminder_template}"); $invoice->service()->touchReminder($reminder_template)->save(); $fees = $this->calcLateFee($invoice, $reminder_template); @@ -149,7 +149,7 @@ class ReminderJob implements ShouldQueue $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) { EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); - nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); + nrlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); $invoice->entityEmailEvent($invitation, $reminder_template); $invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client"); } @@ -220,7 +220,7 @@ class ReminderJob implements ShouldQueue $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) { EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); - nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); + nrlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); $invoice->entityEmailEvent($invitation, $reminder_template); $invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client"); } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 4434729877..0476aae980 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -488,7 +488,7 @@ class InvoiceService /*When a reminder is sent we want to touch the dates they were sent*/ public function touchReminder(string $reminder_template) - { + { nrlog(now()->format('Y-m-d h:i:s') . " INV #{$this->invoice->number} : Touching Reminder => {$reminder_template}"); switch ($reminder_template) { case 'reminder1': $this->invoice->reminder1_sent = now(); diff --git a/config/logging.php b/config/logging.php index 9a4f1f01f4..b9f74aa68b 100644 --- a/config/logging.php +++ b/config/logging.php @@ -58,7 +58,12 @@ return [ 'level' => env('LOG_LEVEL', 'debug'), 'days' => 7, ], - + 'invoiceninja-reminders' => [ + 'driver' => 'single', + 'path' => storage_path('logs/invoiceninja-reminders.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 90, + ], 'stack' => [ 'driver' => 'stack', 'channels' => ['single'],