2017 © Pedro Peláez
 

library cwh

AWS CloudWatch Handler for Monolog library

image

maxbanton/cwh

AWS CloudWatch Handler for Monolog library

  • Wednesday, May 9, 2018
  • by maxbanton
  • Repository
  • 4 Watchers
  • 103 Stars
  • 325,512 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 27 Forks
  • 2 Open issues
  • 16 Versions
  • 24 % Grown

The README.md

Stand With Ukraine, (*1)

AWS CloudWatch Logs Handler for Monolog

Actions Status Coverage Status License Version Downloads, (*2)

Handler for PHP logging library Monolog for sending log entries to AWS CloudWatch Logs service., (*3)

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

Please press ★ Star button if you find this library useful., (*5)

Disclaimer

This library uses AWS API through AWS PHP SDK, which has limits on concurrent requests. It means that on high concurrent or high load applications it may not work on it's best way. Please consider using another solution such as logging to the stdout and redirecting logs with fluentd., (*6)

Requirements

  • PHP ^7.3
  • AWS account with proper permissions (see list of permissions below)

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

Installation

Install the latest version with Composer by running, (*7)

$ composer require maxbanton/cwh:^2.0

Basic Usage

<?php

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

$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. Set to `null` to allow indefinite retention.
$retentionDays = 30;

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

// Optionally set the JsonFormatter to be able to access your log messages in a structured way
$handler->setFormatter(new JsonFormatter());

// 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

AWS IAM needed permissions

if you prefer to use a separate programmatic IAM user (recommended) or want to define a policy, make sure following permissions are included: 1. CreateLogGroup aws docs 1. CreateLogStream aws docs 1. PutLogEvents aws docs 1. PutRetentionPolicy aws docs 1. DescribeLogStreams aws docs 1. DescribeLogGroups aws docs, (*10)

When setting the $createGroup argument to false, permissions DescribeLogGroups and CreateLogGroup can be omitted, (*11)

AWS IAM Policy full json example

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:DescribeLogGroups"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:DescribeLogStreams",
                "logs:PutRetentionPolicy"
            ],
            "Resource": "{LOG_GROUP_ARN}"
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:PutLogEvents"
            ],
            "Resource": [
                "{LOG_STREAM_1_ARN}",
                "{LOG_STREAM_2_ARN}"
            ]
        }
    ]
}

Issues

Feel free to report any issues, (*12)

Contributing

Please check this document, (*13)


Made in Ukraine 🇺🇦, (*14)

The Versions

09/05 2018

dev-master

9999999-dev

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

09/05 2018

v1.1.9

1.1.9.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

27/04 2018

v1.1.8

1.1.8.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

17/04 2018

v1.1.7

1.1.7.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

29/03 2018

v1.1.6

1.1.6.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

26/03 2018

v1.1.5

1.1.5.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

26/03 2018

v1.1.4

1.1.4.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

02/10 2017

v1.1.3

1.1.3.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

02/09 2017

v1.1.2

1.1.2.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

31/08 2017

v1.1.1

1.1.1.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

31/08 2017

v1.1

1.1.0.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

04/03 2017

v1.0

1.0.0.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

22/11 2016

v0.3

0.3.0.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

09/11 2016

v0.2

0.2.0.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

29/08 2016

v0.1.1

0.1.1.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch

03/07 2016

v0.1

0.1.0.0

AWS CloudWatch Handler for Monolog library

  Sources   Download

MIT

The Requires

 

The Development Requires

monolog aws cloudwatch