Appearance
Error Handling module overview
Table of Contents
Description
The error handling system aims to handle and report all important errors and events on specified channels (.log files, emails, 3rd party services like NewRelic, SMS, etc.). It’s based on top of Laravel’s logger (which itself is based on top of the Monolog library).
For a deeper understanding of the system, you should read the following docs:
This document assumes that you have already read the docs from the list above.
How it works
The system is registered in bootstrap/app.php (look for configureMonologUsing method) and works in 2 cases:
- when you call
Log::debug,Log::infoor any other method of the\Illuminate\Support\Facades\Log::class. - when exception handler catch en exception (including PHP Fatal error and other Throwable objects).
Depending on the severity level and environment, it uses different sets of handlers (email, SMS, etc.).
Log levels
| level | description |
|---|---|
| debug | Detailed debug information. |
| info | Interesting events. Examples: User logs in from a new place. |
| notice | Normal but significant events |
| warning | Exceptional occurrences that are not errors. Examples: Use of deprecated APIs |
| error | Runtime errors that do not require immediate action but should typically be logged and monitored. |
| critical | Critical conditions. Example: Application component unavailable |
| alert | Action must be taken immediately. Example: Entire website down |
| emergency | Emergency: system is unusable, huge security vulnerability |
Handlers
| Weight / Level | 100: debug | 200: info | 250: notice | 300: warning | 400: error | 500: critical | 550: alert | 600: emergency |
|---|---|---|---|---|---|---|---|---|
| Daily log file | V | V | V | V | V | V | V | V |
| New Relic | V | V | V | V | V | V | ||
| Errorlog | V | V | V | V | ||||
| Slack | V | V | V |
Errorlog handler
PHP has a built-in error logging system using the error_log() method. Our servers are configured to use /var/log/php_errors.log file to store all events created by error_log.
New Relic handler
To provide the PHP exception stack trace to New Relic, you should pass an array that includes your exception available by exception key as a second parameter to the Log::{level} method:
php
try {
doSomethingWhichMayThrowAnException();
} catch (S3Exception $s3exception) {
Log::alert($s3exception->getMessage(), ['exception' => $s3exception]);
} catch (\Exception $exception) {
Log::warning($exception->getMessage(), ['exception' => $exception]);
}Error Handling system vs. Activity Logging system
Activity Logging system is intended to log some important (in terms of member support) user and script activity.