What is correct method to access Laravel logs from application start.php-ThrowExceptions

Exception or error:

Sorry if this seems a dumb question but I am learning how the Laravel framework operates.
I have a working web app that uses the Laravel framework. The log file is set in backend/app/start/global.php

| Application Error Logger
| Here we will configure the error logger setup for the application which
| is built on top of the wonderful Monolog library. By default we will
| build a rotating log file setup which creates a new file each day.

$logFile = 'log-'.php_sapi_name().'.txt';

Log::info('Log file set to '.$logFile);

The last line Log::info() I added to the file and it works ok.
However i need to add similar info logging messages to backend/bootstrap/start.php. I now want to add a Log::info() statement.
I have reference to the Laravel application via the line in start.php

$app = new Illuminate\Foundation\Application;

So my question is; if I am using the Laravel framework what is the correct way to get a reference to the Laravel “Log” defined in global.php. So that I can add a line such as:

Log::info('Using Environment '.$key);
How to solve:

This is what you need to get a reference to Log class.

use Illuminate\Support\Facades\Log;


Using $app['log']->info('Stuff you want to log') should work but I don’t think that’s a good idea.

This file exists only to create the “app” but you shouldn’t need to do anything inside since the config files aren’t even loaded that’s why you can’t use Facades here, no config file => no Facades.

Leave a Reply

Your email address will not be published. Required fields are marked *