Skip to content

getting LogToDB instance in SaveNewLogEvent #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Jobs/SaveNewLogEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace danielme85\LaravelLogToDB\Jobs;

use danielme85\LaravelLogToDB\Models\DBLogException;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -15,11 +14,10 @@ class SaveNewLogEvent implements ShouldQueue
/**
* Create a new job instance.
*
* @param object $logToDb
* @param \Monolog\LogRecord $record
* @return void
*/
public function __construct(protected object $logToDb, protected LogRecord $record)
public function __construct(protected LogRecord $record)
{
}

Expand All @@ -30,6 +28,6 @@ public function __construct(protected object $logToDb, protected LogRecord $reco
*/
public function handle()
{
$this->logToDb->safeWrite($this->record);
app('laravel-log-to-db')->safeWrite($this->record);
}
}
8 changes: 4 additions & 4 deletions src/LogToDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ public function newFromMonolog(LogRecord $record)
}
if (!empty($this->config['queue'])) {
if (empty($this->config['queue_name']) && empty($this->config['queue_connection'])) {
dispatch(new SaveNewLogEvent($this, $record));
dispatch(new SaveNewLogEvent($record));
} else if (!empty($this->config['queue_name']) && !empty($this->config['queue_connection'])) {
dispatch(new SaveNewLogEvent($this, $record))
dispatch(new SaveNewLogEvent($record))
->onConnection($this->config['queue_connection'])
->onQueue($this->config['queue_name']);
} else if (!empty($this->config['queue_connection'])) {
dispatch(new SaveNewLogEvent($this, $record))
dispatch(new SaveNewLogEvent($record))
->onConnection($this->config['queue_connection']);
} else if (!empty($this->config['queue_name'])) {
dispatch(new SaveNewLogEvent($this, $record))
dispatch(new SaveNewLogEvent($record))
->onQueue($this->config['queue_name']);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/LogToDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function testSaveNewLogEventJob()
formatted: "[2019-10-04T17:26:38.446827+00:00] local.INFO: test [] []\n",
);

$job = new SaveNewLogEvent($logToDb, $record);
$job = new SaveNewLogEvent($record);
$job->handle();

$this->assertNotEmpty($logToDb->model()->where('message', '=', 'job-test')->get());
Expand Down