felixmaier1989/maxbanton-cwh

AWS CloudWatch Handler for Monolog library

v1.1.32 2017-10-17 04:44 UTC

This package is auto-updated.

Last update: 2024-12-04 20:39:58 UTC


README

Build Status Coverage Status License Version Downloads

Handler for PHP logging library Monolog for sending log entries to AWS CloudWatch Logs service.

Before using this library, it's recommended to get acquainted with the pricing for AWS CloudWatch services.

Please press ★ Star button if you find this library useful, aslo you can donate if you like to.

Features

  • Up to 10000 batch logs sending in order to avoid Rate exceeded errors
  • Log Groups creating with tags
  • AWS CloudWatch Logs staff lazy loading
  • Suitable for web applications and for long-living CLI daemons and workers
  • Compatible with PHP 5.6 / 7.0 / 7.1

Installation

Install the latest version with Composer

$ composer require maxbanton/cwh:^1.0

Upgrade

Change in your composer.json

{
  "require": {
    "maxbanton/cwh": "^0.0.3"
  }
}

to

{
  "require": {
    "maxbanton/cwh": "^1.0"
  }
}

then run

$ composer update

and change your code

<?php
// Instantiate handler
$handler = new CloudWatch($client, $logGroupName, $logStreamName, $daysToRetention);

to

<?php
// Instantiate handler (tags are optional)
$handler = new CloudWatch($client, $groupName, $streamName, $retentionDays, 10000, ['my-awesome-tag' => 'tag-value']);

Basic Usage

<?php

use Aws\CloudWatchLogs\CloudWatchLogsClient;
use Maxbanton\Cwh\Handler\CloudWatch;
use Monolog\Logger;

$sdkParams = [
    'region' => 'eu-west-1',
    'version' => 'latest',
    'credentials' => [
        'key' => 'your AWS key',
        'secret' => 'your AWS secret',
        'token' => 'your AWS session token', // token is optional
    ]
];

// Instantiate AWS SDK CloudWatch Logs Client
$client = new CloudWatchLogsClient($sdkParams);

// Log group name, will be created if none
$groupName = 'php-logtest';

// Log stream name, will be created if none
$streamName = 'ec2-instance-1';

// Days to keep logs, 14 by default
$retentionDays = 30;

// Instantiate handler (tags are optional)
$handler = new CloudWatch($client, $groupName, $streamName, $retentionDays, 10000, ['my-awesome-tag' => 'tag-value']);

// Create a log channel
$log = new Logger('name');

// Set handler
$log->pushHandler($handler);

// Add records to the log
$log->debug('Foo');
$log->warning('Bar');
$log->error('Baz');

Frameworks integration

And many others

Issues

Feel free to report any issues

Contributing

Please check this document

Donate

If you would like to, you can send any amount of BTC to the wallet 12d3VXfvPiQ5bFMfPppGqpwnNSkZwigBVt