I have to create separate log files for the companies Laravel 5. I have already done this in Laravel by just putting my logic in global.php file. This makes it easy to trace the errors if a specific company admin puts a complaint. Anyway, in Laravel 5 the whole structure is changed for the framework.
I've tried to override ConfigureLogging class in bootstrap directory. Every thing was going fine but suddenly when it came on an eloquent query, which I needed there, Laravel thrown error Call to a member function connection() on null which means I'm trying to use Laravel services before they get started.
So, I want to know that Where else the following code I should put that it might work perfectly to change the Logging behavior (only to use separate log file for each company).
Here is my code:
$companyId = isset($_COOKIE['companyId'])?$_COOKIE['companyId']:null;
if(!(is_null($companyId))){
$today = date('d-m-Y');
if(!file_exists(storage_path().'/logs/'.$today)){
// I've created the Filesystem instance as File Facade was not working here.
$file = new Filesystem;
$file->makeDirectory(storage_path(). '/logs/' . $today, 0777);
}
// No problem till here
$company = Company::find($companyId); // This is the line where Laravel is throwing error
$companyName = str_replace(' ', '_', $company->name).'_'.$companyId;
$log->useDailyFiles($app->storage_path().'/logs/'.$today.'/'.$companyName.'.log', $app->make('config')->get('app.log_max_files', 5), $app->make('config')->get('app.log_max_files'), Config::get('app.log_level'));
}elseif(is_null($companyId)){
$log->useDailyFiles($app->storagePath().'/logs/laravel.log', $app->make('config')->get('app.log_max_files', 5));
}
I'm thinking to use mysqli here for database connection and query. But it's not a good solution that I use Core PHP in Laravel Framework.
Can I change Logging behavior in any other way i.e. using Service Providers or something else?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Qhbypq
via IFTTT
Aucun commentaire:
Enregistrer un commentaire