Download the PHP package aporat/laravel-cloudwatch-logger without Composer

On this page you can find all versions of the php package aporat/laravel-cloudwatch-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cloudwatch-logger

Laravel CloudWatch Logger

Latest Stable Version Downloads Codecov Laravel Version GitHub Actions Workflow Status

A Laravel logging driver for AWS CloudWatch Logs.

Features

Requirements

Installation

The service provider is auto-discovered. It registers a cloudwatch logging channel from the package defaults, so this already works:

To customise it, publish the config:

The published config/cloudwatch-logger.php is a complete channel definition. If you define a cloudwatch channel yourself in config/logging.php, yours wins and the package leaves it alone.

Defining channels

A channel is a normal Laravel custom driver entry:

Leave both credential values empty to use the AWS default credential chain (IAM task/instance role, environment variables, ~/.aws/credentials). The empty block is removed before the client is built, so the SDK doesn't reject it.

Options

Key Type Default Description
aws array — Passed to the CloudWatchLogsClient constructor. region and version are required.
group string — Log group. Letters, digits, _, -, /, ., #; max 512 chars.
stream string — Log stream within the group. No : or *; max 512 chars. Supports placeholders.
stream_date_format string Y-m-d PHP date() format for {date}, evaluated in UTC.
name string — Monolog channel name, used by %channel%.
level string|int|Level debug Minimum level. Accepts a Monolog\Level, a severity number, or a level name.
formatter string|class|instance|callable LineFormatter See Formatters.
formatter_with array [] Constructor arguments for a formatter class, as in Laravel.
handler class CloudWatchHandler A CloudWatchHandler subclass to build instead. See Customising the handler.
handler_with array [] Named CloudWatchHandler constructor arguments that override the computed ones.
replace_placeholders bool false Interpolate {placeholders} from the context, as Laravel's other channels do.
retention int|null 14 Days to retain events, or null to never expire. Must be one of CloudWatch's accepted periods. Applied when this package creates the group, or to an existing group with enforce_group_settings.
batch_size int 10000 Buffered events that trigger a send. 1–10000.
flush_interval int 10 Seconds; a write flushes the buffer once its oldest event is this old. 0 disables.
max_buffer_size int 10000 (or batch_size if larger) Hard cap on buffered events. Beyond it the oldest are dropped and counted. Must be ≥ batch_size.
rps_limit int 0 Max PutLogEvents calls per second from one process; 0 disables.
tags array<string,string> [] Tags applied when the group is created, or to an existing group with enforce_group_settings.
enforce_group_settings bool false Also apply retention and tags to a group that already exists. See Existing log groups.
bubble bool true Whether records continue to other handlers.
create_group bool true Create the log group if missing.
create_stream bool true Create the log stream if missing.
cache bool|string|class|pool false See Avoiding the per-process describe calls.
cache_ttl int 300 Lifetime, in seconds, of a cached "group/stream exists" (or "settings applied") marker.
suppress_failures bool true Report CloudWatch failures with error_log() instead of throwing out of the log call.
circuit_breaker int 30 Seconds to stop sending after a failed request; 0 disables.
fallback_channel string|null null A log channel that receives records CloudWatch could not take. See Fallback channel.

Every scalar option also accepts the string form env() produces, so CLOUDWATCH_LOG_BATCH_SIZE=25 and 'batch_size' => 25 behave identically.

AWS client defaults

Unless you set them in aws, the package adds:

so an unreachable or black-holed endpoint costs a few seconds once (then the circuit breaker takes over) instead of minutes per log call. Any value you set wins. Prefer an integer retries: the SDK passes the client's retries to its default credential provider, and off EC2 with no other credentials an array value (['mode' => 'standard', …]) makes it retry the instance metadata service indefinitely.

Buffering and delivery

Records are buffered in memory and sent with PutLogEvents when any of these happens:

flush_interval is checked on write: a long-running process that does not use the queue worker or Octane (a custom daemon loop, for example) should call close() or reset() on the logger at the end of each unit of work.

Every request respects the API limits whatever batch_size is: at most 10,000 events and 1,048,576 bytes (message bytes + 26 per event), in chronological order, spanning less than 24 hours. A single event can be up to 1 MB (1,048,576 bytes including the 26-byte overhead; CloudWatch raised this from 256 KB in 2025), so a message larger than 1,048,550 bytes is split into several events on UTF-8 character boundaries; invalid UTF-8 is scrubbed. Timestamps are sent as integer milliseconds. No sequence tokens are used: CloudWatch has ignored them since January 2023.

When CloudWatch fails

CloudWatchHandler::getDroppedEventCount(), getBufferedEventCount() and isCircuitOpen() expose this state.

rps_limit paces one process only. CloudWatch's PutLogEvents quota is per account and region (5,000 requests/second by default, adjustable); the old 5-requests-per-second-per-stream limit was removed in January 2023, so many processes can write to the same stream.

Fallback channel

fallback_channel names another Laravel log channel (for example single, daily or stderr) that receives the records CloudWatch could not take:

While the circuit is open records stay buffered and are retried, so nothing is written twice: a record goes to the fallback only once CloudWatch has definitely not received it. Records keep their level, message, context and time; the reason is added to the context as cloudwatch_fallback (buffer full, rejected by CloudWatch or undelivered when the handler closed).

The fallback must not write to CloudWatch. A channel using this package's factory (or a stack containing one) is refused when the channel is built, and at runtime a fallback logger that holds a CloudWatchHandler is refused and reported. While records are being forwarded the CloudWatch handler ignores anything written to it, so even a misconfigured fallback cannot loop.

Avoiding the per-process describe calls

By default the handler issues a DescribeLogGroups and a DescribeLogStreams call on the first write of every process, for every channel, to find out whether it needs to create them. Set cache to remember the answer:

Cache keys identify the group and the group/stream pair separately, so a stream named like its group, or two groups sharing a stream name, never share an entry, and any PSR-6 pool accepts them. Cache failures degrade to a miss — the handler just asks CloudWatch again.

If the group and stream are provisioned outside the application (Terraform, CloudFormation), set create_group and create_stream to false instead and skip the lookups entirely.

Stream name placeholders

stream may contain:

Placeholder Value Resolved
{hostname} gethostname() when the channel is built
{pid} getmypid() when the channel is built
{env} the application environment (app.env) when the channel is built
{date} the event's date in UTC, formatted with stream_date_format (default Y-m-d) per event

{date} is taken from each record's own timestamp, in UTC, not from when the channel was built. A queue worker or Octane server that runs past midnight UTC therefore starts writing to the next day's stream with the first record of the new day, and records buffered across midnight go to their own day's stream. The new stream is created (or found) on the first flush that needs it. Other {…} text is left as is. The expanded name is validated like any stream name, so a format that produces : (such as H:i) is rejected up front.

{pid} gives every PHP-FPM worker its own stream; combine it with care, since each new stream costs a CreateLogStream call.

Existing log groups

By default retention and tags are only applied when the package creates the log group. Set enforce_group_settings to true to apply them to a group that already exists:

This runs on the first flush of each process — or once per cache_ttl when cache is set; the cache entry includes the desired retention and tags, so changing them re-applies them. A failure (for example a missing logs:PutRetentionPolicy or logs:TagResource permission) is reported with error_log() and never blocks logging; it is retried by the next process.

Testing the connection

The command validates the channel configuration, resolves AWS credentials, checks (and, unless --dry-run, creates) the log group and stream, applies group settings when enforce_group_settings is on, and sends one test event. It reports each step with a result and timing and exits non-zero if any step fails. Secrets are never printed; only the last four characters of the access key ID are shown.

A missing permission is named in the failing step (for example access denied: grant logs:DescribeLogGroups) and the steps that depend on it are skipped.

IAM permissions

What the package calls depends on the options:

Action Needed for
logs:PutLogEvents always
logs:DescribeLogStreams, logs:CreateLogStream create_stream (default)
logs:DescribeLogGroups, logs:CreateLogGroup create_group (default)
logs:PutRetentionPolicy retention on a group the package creates, or enforce_group_settings
logs:TagResource tags on a group the package creates (tagging at creation needs it), or enforce_group_settings
logs:DescribeLogGroups enforce_group_settings, and cloudwatch:test

DescribeLogGroups does not support resource-level permissions, so it needs "Resource": "*". Group-level actions use the log group ARN (arn:aws:logs:REGION:ACCOUNT:log-group:NAME); stream-level actions (CreateLogStream, PutLogEvents) use the stream ARN (…:log-group:NAME:log-stream:STREAM). DescribeLogGroups and many existing policies still use the older log group form with a trailing :*, so the examples list both.

Sending only, with the group and stream provisioned elsewhere (create_group and create_stream set to false):

Everything: creating the group and streams, retention, tags and enforce_group_settings:

Drop logs:PutRetentionPolicy / logs:TagResource if you use neither retention nor tags, and logs:CreateLogGroup with create_group off.

Scoping examples:

Action names and resource types are as listed for CloudWatch Logs in the AWS Service Authorization Reference.

Failure handling

By default a log write never throws because of CloudWatch (see When CloudWatch fails). Set 'suppress_failures' => false to have a failed send throw out of the log call instead — note that in a request path that logs its own errors, or in Laravel's exception handler, that exception replaces the one being reported.

To keep the records CloudWatch could not take, set a fallback_channel. For a local copy of everything, use a Laravel stack channel:

Formatters

formatter accepts these shapes:

Forms 3 and 4 (and a cache pool instance) cannot be serialized by php artisan config:cache; use a class name (with formatter_with) if you cache your configuration.

formatter_with follows Laravel: named arguments are passed to the container (app()->make($class, $with)); a positional list is passed to the constructor in order. It is an error to set it without a formatter class.

Customising the handler

Like Laravel's monolog driver, handler_with passes named constructor arguments to the handler. They override the values computed from the rest of the config, which makes the less common CloudWatchHandler arguments reachable while keeping the config cacheable:

handler may name a CloudWatchHandler subclass. It is resolved through the container with the computed arguments (plus handler_with), so it can add its own dependencies:

A string that looks like a class name but doesn't resolve to a FormatterInterface is rejected, rather than being silently used as a format template.

Configuration errors

Invalid configuration throws Aporat\CloudWatchLogger\Exceptions\IncompleteCloudWatchConfig while the channel is being built.

Note that Laravel's LogManager catches anything a channel factory throws and substitutes its emergency file logger (storage/logs/laravel.log). So a misconfigured channel does not raise at the call site — it stops reaching CloudWatch, and the reason is written to the emergency log. Worth checking there if a channel goes quiet after a config change, or run php artisan cloudwatch:test, which reports the error directly.

Upgrading from 3.x

4.0 replaces the phpnexus/cwh handler with the package's own Aporat\CloudWatchLogger\Handler\CloudWatchHandler.

Testing

CI runs the suite on PHP 8.3, 8.4 and 8.5 against Laravel 12 and 13, plus the lowest dependency versions composer.json allows.

Contributing

See SECURITY.md.

License

MIT. See LICENSE.


All versions of laravel-cloudwatch-logger with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-mbstring Version *
aws/aws-sdk-php Version ^3.300
illuminate/contracts Version ^12.0 || ^13.0
illuminate/log Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
monolog/monolog Version ^3.6
psr/cache Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aporat/laravel-cloudwatch-logger contains the following files

Loading the files please wait ...