Skip to content

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::info or 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

leveldescription
debugDetailed debug information.
infoInteresting events. Examples: User logs in from a new place.
noticeNormal but significant events
warningExceptional occurrences that are not errors. Examples: Use of deprecated APIs
errorRuntime errors that do not require immediate action but should typically be logged and monitored.
criticalCritical conditions. Example: Application component unavailable
alertAction must be taken immediately. Example: Entire website down
emergencyEmergency: system is unusable, huge security vulnerability

Handlers

Weight / Level100: debug200: info250: notice300: warning400: error500: critical550: alert600: emergency
Daily log fileVVVVVVVV
New RelicVVVVVV
ErrorlogVVVV
SlackVVV

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.