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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners