Source: nico.orfanos.dev

Nico Orfanos
A thing in all my projects is using Elastic cloud for my application logging. The reason for this is that, it’s super easy to start logging in https://www.elastic.co/de/ with Laravel. With ~20$ a month you can have a small Elasticsearch & Kibana setup ready the receive logs from your application.

Next we add an elastic custom logging driver to config/logging.php file 'elastic' => [ 'driver' => 'custom', 'via' => \App\Logging\ElasticLogger::class, 'cloud_id' => env('ELASTIC_CLOUD_ID', null), 'password' => env('ELASTIC_PASSWORD', null), 'prefix' => env('ELASTIC_INDEX_PREFIX', \Illuminate\Support\Str::slug(env('APP_NAME', 'laravel'), '_')), ], and we create our custom ElasticLogger class in app/Logging/ElasticLogger.php with the following format('Y_m_d'); $client = ClientBuilder::create() ->setElasticCloudId($config['cloud_id']) ->setBasicAuthentication('elastic', $config['password']) ->build(); $handler = new ElasticsearchHandler($client); $handler->setFormatter(new ElasticsearchFormatter($index, '_doc')); $monolog = new MonologLogger('elastic', [$handler]); return (new Logger($monolog))->withContext(['env' => config('app.env')]); }}

Now you can use the Log facade and all logs from your application will land at one place.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners