Monolog integration

The Monolog integration supports Monolog version 1, version 2 and version 3.

Install

composer require async-aws/monolog-cloud-watch

Usage

use AsyncAws\CloudWatchLogs\CloudWatchLogsClient; use AsyncAws\Monolog\CloudWatch\CloudWatchLogsHandler; use Monolog\Logger; $client = new CloudWatchLogsClient(); $handler = new CloudWatchLogsHandler($client, [ 'group' => 'company-website', 'stream' => 'frontend-api', ]); $logger = new Logger('logger'); $logger->pushHandler($handler); $logger->error('an error occurred');

Configuration

The CloudWatchLogsHandler accepts the following parameters:

For the $options parameter, the allowed values are:

Symfony usage

To ease service configuration, install the AsyncAws Symfony Bundle first.

The bundle will automatically configure CloudWatchLogsClient with the given credentials.

# config/services.yaml services: app.monolog_handler.cloud_watch: class: AsyncAws\Monolog\CloudWatch\CloudWatchLogsHandler arguments: - '@async_aws.client.cloud_watch_logs' - group: company-website stream: frontend-api # more parameters, see Configuration
# config/packages/prod/monolog.yaml monolog: handlers: main: type: fingers_crossed action_level: error handler: cloud_watch cloud_watch: type: service id: app.monolog_handler.cloud_watch

Limitations

The CloudWatchLogs Monolog relies on the AWS CloudWatch Logs API and inherits the underlying limitations, which are described in the official documentation.

The integration enforces a few limitations like the maximum batch size, maximum number of events per batch and chronological order of events; which should not be taken care of by the developer.

CloudWatch Logs throttles PutLogEvents requests according to a per-account quota. The quota can be increased through AWS Service Quotas. A batch can contain at most 10,000 log events.

The AWS credentials should have at least the logs:DescribeLogStreams and logs:PutLogEvents permissions for the integration to work properly.