jenssegers / laravel-rollbar

Rollbar error monitoring integration for Laravel projects
328 stars 98 forks source link

use specified rollbar person_fn function (updated version) #35

Closed jnbn closed 8 years ago

jnbn commented 8 years ago

You can now assign and use person_fn from config file and use any user-defined helper function to pass person data to rollbar object.

'rollbar' => array(
        'access_token' => 'XXX',
        'person_fn' => 'get_rollbar_user',
        'level' => 'debug'
    ),
function get_rollbar_user() {
    if (Auth::check()) {
        $user = Auth::user();
        return array(
            'id' => $user->id, // required - value is a string
            'username' => $user->fullName(), // required - value is a string
            'email' => $user->email, // optional - value is a string
        );
    }
    return null;
}
xitude commented 8 years ago

Could you be more helpful by telling us where we could implement the function in a stock laravel 5.1~ project.

jnbn commented 8 years ago

Hi xitude,

You can create your helper file which includes get_rollbar_user function like

<?php
function get_rollbar_user() {
    if (Auth::check()) {
        $user = Auth::user();
        return array(
            'id' => $user->id, // required - value is a string
            'username' => $user->fullName(), // required - value is a string
            'email' => $user->email, // optional - value is a string
        );
    }
    return null;
}

and load it from composer by adding it manually to the files array under autoload like

...
"autoload": {
        "classmap": [
            "database"
        ],
        "files": ["app/Http/helpers.php"], // location of the file you created
        "psr-4": {
            "App\\": "app/"
        }
    },
...
xitude commented 8 years ago

Perfect. Thanks :+1: