Skip to content

Commit

Permalink
fix: log-driver undefined index issue solved
Browse files Browse the repository at this point in the history
  • Loading branch information
arif98741 committed May 24, 2024
1 parent 3014e87 commit 5178433
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
14 changes: 11 additions & 3 deletions src/Config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,22 @@
*-----------------------------------------------------------------------------------------------
| Sms Log will save sms request, provider name, and response in database table called `lbs_log`
| You can change sms log to true/false according to your need. Default is set to true
|---------------------------------------------------------------------------------------------
|-----------------------------------------------------------------------------------------------
*/
'sms_log' => false,

/*
*-----------------------------------------------------------------------------------------------
| Sms log will be saved in database(lbs_log table) or file(storage/logs/laravel.log).
| You can choose one according to need
|-----------------------------------------------------------------------------------------------
*/
'log_driver' => 'database', //database, file

/*
*-----------------------------------------------------------------------------------------------
| Default provider will be used during usage of facade( Xenon\LaravelBDSms\Facades\SMS )
|---------------------------------------------------------------------------------------------
|-----------------------------------------------------------------------------------------------
*/
'default_provider' => env('SMS_DEFAULT_PROVIDER', Ssl::class),
/*
Expand All @@ -79,7 +87,7 @@
| This providers key store all the necessary credentials needed for using inside .env file; Be sure to use this
| credentials in your .env file before sending sms. This will be used while you are sending sms using
| facade(Xenon\LaravelBDSms\Facades\SMS)
|-------------------------------------------------------------------------------------------------------------
|---------------------------------------------------------------------------------------------------------------
*/
'providers' => [
Adn::class => [
Expand Down
13 changes: 9 additions & 4 deletions src/Job/SendSmsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log as LaravelLog;
use Illuminate\Support\Facades\Log as LaravelLog;
use JsonException;
use Xenon\LaravelBDSms\Facades\Logger;

Expand Down Expand Up @@ -142,10 +142,15 @@ private function insertLoggerLog(array $log): void
$config = Config::get('sms');
if ($config['sms_log']) {

if ($config['log_driver'] === 'database') {
if (array_key_exists('log_driver', $config)) {

if ($config['log_driver'] === 'database') {
Logger::createLog($log);
} else if ($config['log_driver'] === 'file') {
LaravelLog::info('laravelbdsms', $log);
}
} else {
Logger::createLog($log);
} else if ($config['log_driver'] === 'file') {
LaravelLog::info('laravelbdsms',$log);
}
}
}
Expand Down
31 changes: 18 additions & 13 deletions src/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,26 @@ private function logGenerate($config, $response): void
'message' => $this->getMessage()
];

if ($config['log_driver'] === 'database') {
$logData = [
'provider' => $providerClass,
'request_json' => json_encode($requestData, JSON_THROW_ON_ERROR),
'response_json' => json_encode($providerResponse, JSON_THROW_ON_ERROR)
];
$logData = [
'provider' => $providerClass,
'request_json' => json_encode($requestData, JSON_THROW_ON_ERROR),
'response_json' => json_encode($providerResponse, JSON_THROW_ON_ERROR)
];

if (array_key_exists('log_driver', $config)) {

if ($config['log_driver'] === 'database') {
Logger::createLog($logData);
} elseif ($config['log_driver'] === 'file') {
$logData['request_json'] = $requestData;
$logData['response_json'] = $providerResponse;
LaravelLog::info('laravelbdsms', $logData);
}
} else {

Logger::createLog($logData);
} elseif ($config['log_driver'] === 'file') {
$logData = [
'provider' => $providerClass,
'request_json' => $requestData,
'response_json' => $providerResponse,
];
LaravelLog::info('laravelbdsms', $logData);
}

}
}

Expand Down

0 comments on commit 5178433

Please sign in to comment.