Forward Laravel Logs to Amazon Kinesis

Packages

March 4th, 2022

laravel-monolog-kinesis.png

The Laravel Monolog Kinesis package makes it simple to forward Laravel application logs to an AWS Kinesis stream.

Once you've configured a kinesis service in the config/services.php file, you can set up a logging channel in the config/logging.php file:

1'some_channel' => [
2 'driver' => 'kinesis',
3 'stream' => 'some_stream_name',
4 'level' => 'info', // default level is debug
5],

If you have custom needs, you can set a different key, secret, and region at the channel level:

1'some_channel' => [
2 'driver' => 'kinesis',
3 'stream' => env('LOGGING_KINESIS_STREAM'),
4 'level' => env('LOG_LEVEL', 'debug'),
5 'key' => env('AWS_ACCESS_KEY_ID'),
6 'secret' => env('AWS_SECRET_ACCESS_KEY'),
7 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
8],

Under the hood, the package uses the AWS SDK (v3.x) Kinesis client to send records to the service after formatting logs via the package's custom formatter.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.

Laravel News Partners