Im trying to write a custom log for my laravel application, as the application is quite large so I want to organise my log files.
The issue is, if at any point the application errors, it writes to the laravel.log file and kills the script, as php does.
So for example, I have a custom log library like so
<?php
namespace App\Libraries\Logs;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Log;
class CustomLogsLibrary {
public function userError($error){
$orderLog = new Logger('users');
$orderLog->pushHandler(new StreamHandler(storage_path('logs/users.log')), Logger::INFO);
$orderLog->info('Error 1', $error);
}
}
and then if this is my script
$user = new User;
$user->nae = $request->name; //Name spelt wrong on purpose
$user->email = $request->email;
$user->password = bcrypt($request->password);
if(!$user->save()){
$errorCode = (new CustomLogsLibrary)->userError($user->save());
}
As you can probably see i've spelt 'name' wrong in the user object to force an error.
Laravel then errors on the misspelt name and dies, meaning it never actually reaches my custom log function, instead it logs
Column not found: 1054 Unknown column 'nme' in 'field list'
to laravel.log and then dies. I know it will hit the function if the false is returned, but when false is not returned and the function errors for a different reason, I still want to log it in a custom file.
How do I get around this?
I want to be able to organise all errors into separate files, and prioritise writing to those files over the standard laravel.log file.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire