File tree Expand file tree Collapse file tree 4 files changed +51
-5
lines changed
Expand file tree Collapse file tree 4 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,21 @@ Add the following lines in your `config/logging.php`:
1818'db' => [
1919 'driver' => 'custom',
2020 'via' => VisualAppeal\DatabaseLogger\DatabaseLogger::class,
21- 'level' => env('LOG_LEVEL', 'debug'),
21+ 'level' => env('LOG_LEVEL', 'debug'), // Optional
22+ 'connection' => env('LOG_DATABASE', 'mysql'), // Optional
23+ 'table' => env('LOG_TABLE', 'logs'), // Optional
2224],
2325```
2426
2527## Change log
2628
29+ ### 1.2.1
30+
31+ * FEATURE: Usage of custom database connections or tables
32+
2733### 1.2.0
2834
29- * New logging class compatible to Laravel 5.6
35+ * FEATURE: New logging class compatible to Laravel 5.6
3036
3137### 1.0.0
3238
Original file line number Diff line number Diff line change 1818 }
1919 ],
2020 "require" : {
21- "php" : " >=5.6 " ,
21+ "php" : " >=7.0 " ,
2222 "illuminate/support" : " 5.6.*"
2323 },
2424 "autoload" : {
Original file line number Diff line number Diff line change 88
99class DatabaseHandler extends AbstractProcessingHandler
1010{
11+ /**
12+ * Name of the database connection.
13+ *
14+ * @var string
15+ */
16+ protected $ connection ;
17+
18+ /**
19+ * connection table name.
20+ *
21+ * @var string
22+ */
23+ protected $ table ;
24+
25+ /**
26+ * Set the database connection name.
27+ *
28+ * @param string $connection
29+ */
30+ public function setConnection (string $ connection ): void
31+ {
32+ $ this ->connection = $ connection ;
33+ }
34+
35+ /**
36+ * Set the database table name.
37+ *
38+ * @param string $table
39+ */
40+ public function setTable (string $ table ): void
41+ {
42+ $ this ->table = $ table ;
43+ }
44+
1145 /**
1246 * {@inheritdoc}
1347 */
@@ -24,7 +58,7 @@ protected function write(array $record)
2458 }
2559
2660 try {
27- DB ::table (' logs ' )->insert ([
61+ DB ::connection ( $ this -> connection )-> table ($ this -> table )->insert ([
2862 'message ' => $ record ['message ' ],
2963 'context ' => $ context ,
3064 'level ' => $ record ['level ' ],
Original file line number Diff line number Diff line change @@ -15,7 +15,13 @@ class DatabaseLogger
1515 public function __invoke (array $ config )
1616 {
1717 $ logger = new Logger ('laravel.database ' );
18- $ logger ->pushHandler (new DatabaseHandler ($ config ['level ' ] ?? 'debug ' ));
18+
19+ $ handler = new DatabaseHandler ($ config ['level ' ] ?? 'debug ' );
20+ $ handler ->setConnection ($ config ['connection ' ] ?? 'mysql ' );
21+ $ handler ->setTable ($ config ['table ' ] ?? 'logs ' );
22+
23+ $ logger ->pushHandler ($ handler );
24+
1925 return $ logger ;
2026 }
2127}
You can’t perform that action at this time.
0 commit comments