Last Updated: February 25, 2016
· cossou

Catch errors in your L4 application

Hey guys! My name is Hélder and I'm writing from Lisbon, Portugal.

In my latest project I was not sure how to handle the Exceptions (that will eventually occur) on the production server, without having to SSH and manually check the logs. So I came across, a web app to collect errors from your app and organize them.

Moving on… In this short protip I will cover how you can control your app errors when it is in production.

For that we will use the awesome web app called:
A short description from their site:

Airbrake collects errors generated by other applications, and aggregates the results for review.

First of all, we need an account! If you don't have one, go and grab one at They have many plans (including a free one).

Getting started

I'm assuming that you already have composer installed. If not got to

First we need to add the Airbrake composer package:

"airbrake/airbrake-php": "dev-master",

to our composer.json file and then composer update.

Notice something? Its not a specific L4 composer package. So we don't need to add the aliases and providers to our config/app.php.

Now that we have the package in our vendor directory we want to start sending all the exceptions to Airbrake.

Let's create a configuration file for our Airbrake API credentials. In the config directory add a new file called airbrake.php with the content:


return array(
    'active'        => true,
    'API'           => 'YOUR-API-KEY',

Simple and clean, right?

Now lets go to the project root and open the start/global.php file and change the App::error function:


App::error(function(Exception $exception, $code)
    // keep saving the exception on the log file.

    // simple on/off mechanism 
        $config = new Airbrake\Configuration(Config::get('airbrake.API'), 
                'async' => true, 
                'environmentName' => App::environment(), 
                'url' => Request::url()
        $client = new Airbrake\Client($config);


Airbrake provide some configuration options. Check it at their GitHub repo.

If you don't want to send errors from you development environment just add a config/local/airbrake.php file with:


return array(
    'active'        => false,

make sure you have the environment set correctly.

And that's it… simple! :)

If you have any questions leave them on the comments or drop me a line on twitter @cossou!


3 Responses
Add your response

This article has a perfect timing. Thank you!

over 1 year ago ·
over 1 year ago ·

Thanks a lot !

over 1 year ago ·