Skip to content

Commit c9da498

Browse files
authored
Merge pull request #70 from ArtemKahramanov/save-new-log-fix
getting LogToDB instance in SaveNewLogEvent
2 parents 026a492 + 059a51b commit c9da498

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/Jobs/SaveNewLogEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace danielme85\LaravelLogToDB\Jobs;
44

5-
use danielme85\LaravelLogToDB\Models\DBLogException;
65
use Illuminate\Bus\Queueable;
76
use Illuminate\Queue\InteractsWithQueue;
87
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -15,11 +14,10 @@ class SaveNewLogEvent implements ShouldQueue
1514
/**
1615
* Create a new job instance.
1716
*
18-
* @param object $logToDb
1917
* @param \Monolog\LogRecord $record
2018
* @return void
2119
*/
22-
public function __construct(protected object $logToDb, protected LogRecord $record)
20+
public function __construct(protected LogRecord $record)
2321
{
2422
}
2523

@@ -30,6 +28,6 @@ public function __construct(protected object $logToDb, protected LogRecord $reco
3028
*/
3129
public function handle()
3230
{
33-
$this->logToDb->safeWrite($this->record);
31+
app('laravel-log-to-db')->safeWrite($this->record);
3432
}
3533
}

src/LogToDB.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ public function newFromMonolog(LogRecord $record)
169169
}
170170
if (!empty($this->config['queue'])) {
171171
if (empty($this->config['queue_name']) && empty($this->config['queue_connection'])) {
172-
dispatch(new SaveNewLogEvent($this, $record));
172+
dispatch(new SaveNewLogEvent($record));
173173
} else if (!empty($this->config['queue_name']) && !empty($this->config['queue_connection'])) {
174-
dispatch(new SaveNewLogEvent($this, $record))
174+
dispatch(new SaveNewLogEvent($record))
175175
->onConnection($this->config['queue_connection'])
176176
->onQueue($this->config['queue_name']);
177177
} else if (!empty($this->config['queue_connection'])) {
178-
dispatch(new SaveNewLogEvent($this, $record))
178+
dispatch(new SaveNewLogEvent($record))
179179
->onConnection($this->config['queue_connection']);
180180
} else if (!empty($this->config['queue_name'])) {
181-
dispatch(new SaveNewLogEvent($this, $record))
181+
dispatch(new SaveNewLogEvent($record))
182182
->onQueue($this->config['queue_name']);
183183
}
184184
} else {

tests/LogToDbTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function testSaveNewLogEventJob()
332332
formatted: "[2019-10-04T17:26:38.446827+00:00] local.INFO: test [] []\n",
333333
);
334334

335-
$job = new SaveNewLogEvent($logToDb, $record);
335+
$job = new SaveNewLogEvent($record);
336336
$job->handle();
337337

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

0 commit comments

Comments
 (0)