|
1 | 1 | # Laravel DevLogger Package |
| 2 | + |
2 | 3 | [](http://choosealicense.com/licenses/mit/) |
3 | 4 |
|
4 | | -`DevLogger` is a comprehensive logging package for Laravel that stores logs in a database with automatic error catching, advanced filtering, and management capabilities. |
| 5 | +`DevLogger` is a comprehensive logging package for Laravel that stores logs in a database with automatic error catching, |
| 6 | +advanced filtering, and management capabilities. |
5 | 7 |
|
6 | 8 | ## Features |
7 | 9 |
|
@@ -102,9 +104,10 @@ try { |
102 | 104 | } |
103 | 105 | ``` |
104 | 106 |
|
105 | | -### Automatic Exception Catching |
| 107 | +### Automatic Exception Catching - Laravel 9, 10, 11 |
106 | 108 |
|
107 | | -The package automatically catches and logs all unhandled exceptions when `DEVLOGGER_AUTO_CATCH=true` (default). To set this up: |
| 109 | +The package automatically catches and logs all unhandled exceptions when `DEVLOGGER_AUTO_CATCH=true` (default). To set |
| 110 | +this up: |
108 | 111 |
|
109 | 112 | #### Option 1: Extend the DevLogger Exception Handler |
110 | 113 |
|
@@ -144,6 +147,31 @@ public function report(Throwable $exception) |
144 | 147 | } |
145 | 148 | ``` |
146 | 149 |
|
| 150 | +### Automatic Exception Catching - Laravel 12 |
| 151 | + |
| 152 | +#### Integration |
| 153 | + |
| 154 | +The bootstrap directory contains the app.php file which bootstraps the framework: `bootstrap/app.php`. Within the |
| 155 | +withException method, you can integrate the DevLogger package to automatically catch exceptions: |
| 156 | + |
| 157 | +```php |
| 158 | + |
| 159 | +->withExceptions(function (Exceptions $exceptions) { |
| 160 | + |
| 161 | + $exceptions->report(function (Throwable $e){ |
| 162 | + if (config('devlogger.auto_catch_exceptions', true)) { |
| 163 | + \DevLoggertPackage\Facades\DevLogger::logException($e, [ |
| 164 | + 'url' => request()?->fullUrl(), |
| 165 | + 'method' => request()?->method(), |
| 166 | + 'input' => request()?->except(['password', 'password_confirmation', '_token']), |
| 167 | + ]); |
| 168 | + } |
| 169 | + return true; |
| 170 | + }) |
| 171 | + |
| 172 | +})->create(); |
| 173 | +``` |
| 174 | + |
147 | 175 | ## Advanced Usage |
148 | 176 |
|
149 | 177 | ### Working with Log Models |
@@ -187,28 +215,28 @@ Automatic cleanup runs daily when `DEVLOGGER_RETENTION_DAYS` is configured. |
187 | 215 |
|
188 | 216 | The `developer_logs` table includes these fields: |
189 | 217 |
|
190 | | -| Field | Type | Description | |
191 | | -|-------|------|-------------| |
192 | | -| `id` | bigint | Primary key | |
193 | | -| `level` | string | Log level (debug, info, error, etc.) | |
194 | | -| `log` | longtext | The log message | |
195 | | -| `context` | json | Additional context data | |
196 | | -| `file_path` | string | File where log originated | |
197 | | -| `line_number` | integer | Line number where log originated | |
198 | | -| `exception_class` | string | Exception class name (for exceptions) | |
199 | | -| `stack_trace` | longtext | Full stack trace (for exceptions) | |
200 | | -| `queue` | string | Associated queue name | |
201 | | -| `request_url` | string | HTTP request URL | |
202 | | -| `request_method` | string | HTTP request method | |
203 | | -| `user_id` | bigint | ID of authenticated user | |
204 | | -| `ip_address` | string | Client IP address | |
205 | | -| `user_agent` | text | Client user agent | |
206 | | -| `status` | string | Log status (open/closed) | |
207 | | -| `tags` | json | Array of tags | |
208 | | -| `updated_by` | bigint | User who last updated the log | |
209 | | -| `created_at` | timestamp | When log was created | |
210 | | -| `updated_at` | timestamp | When log was last updated | |
211 | | -| `deleted_at` | timestamp | Soft delete timestamp | |
| 218 | +| Field | Type | Description | |
| 219 | +|-------------------|-----------|---------------------------------------| |
| 220 | +| `id` | bigint | Primary key | |
| 221 | +| `level` | string | Log level (debug, info, error, etc.) | |
| 222 | +| `log` | longtext | The log message | |
| 223 | +| `context` | json | Additional context data | |
| 224 | +| `file_path` | string | File where log originated | |
| 225 | +| `line_number` | integer | Line number where log originated | |
| 226 | +| `exception_class` | string | Exception class name (for exceptions) | |
| 227 | +| `stack_trace` | longtext | Full stack trace (for exceptions) | |
| 228 | +| `queue` | string | Associated queue name | |
| 229 | +| `request_url` | string | HTTP request URL | |
| 230 | +| `request_method` | string | HTTP request method | |
| 231 | +| `user_id` | bigint | ID of authenticated user | |
| 232 | +| `ip_address` | string | Client IP address | |
| 233 | +| `user_agent` | text | Client user agent | |
| 234 | +| `status` | string | Log status (open/closed) | |
| 235 | +| `tags` | json | Array of tags | |
| 236 | +| `updated_by` | bigint | User who last updated the log | |
| 237 | +| `created_at` | timestamp | When log was created | |
| 238 | +| `updated_at` | timestamp | When log was last updated | |
| 239 | +| `deleted_at` | timestamp | Soft delete timestamp | |
212 | 240 |
|
213 | 241 | ## Configuration Options |
214 | 242 |
|
|
0 commit comments