I have set up the basic example of Laravel lumen with composer create-project --prefer-dist laravel/lumen demo
. I am using Lumen version 8.
My .env file looks like
APP_NAME=Lumen APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost APP_TIMEZONE=UTC LOG_CHANNEL=stack LOG_SLACK_WEBHOOK_URL= DB_CONNECTION=mysql DB_HOST=mysql DB_PORT=3306 DB_DATABASE=mysql DB_USERNAME=root DB_PASSWORD= CACHE_DRIVER=file QUEUE_CONNECTION=sync
I have created a controller TrackerController
and called it in routes/web.php
.
// /app/Http/Controllers/TrackerController.php <?php namespace AppHttpControllers; use IlluminateSupportFacadesLog; use IlluminateHttpRequest; class TrackerController extends Controller { public function index(Request $request) { Log::info('message'); return 'ok'; } }
My /app/routes/web.php
looks like
<?php $router->get('/','TrackerController@index');
I would like to add logging to stdout (so I can later pipe that data to Cloudwatch in AWS ElasticBeanstalk) and from what I understood, this is available out of the box, but I can’t seem to be able to get it to work.
Whenever I execute Log::info('message');
in a controller, I get a A facade root has not been set.
.
Without Log::info('message');
everything is working as intended.
Advertisement
Answer
You should make sure to uncommment the $app->withFacades()
line in your bootstrap/app.php
file. This method sets the application container statically on the Facade class so that each facade can use the container to resolve its ‘root’ (what the facade is the static proxy for).