Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
moesjarraf committed Aug 8, 2017
0 parents commit 122b8ca
Show file tree
Hide file tree
Showing 14 changed files with 3,371 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
/tmp
/vendor
/cache

/tests/_output/
/tests/*/*Tester.php
/tests/_support/_generated
/nbproject
30 changes: 30 additions & 0 deletions .travis.yml
@@ -0,0 +1,30 @@
language: php
php: 5.5
sudo: false

before_install:
# Configure Git
- git config --global user.email "travis-ci@legalthings.net"
- git config --global user.name "Travis CI"

# Configure composer
- test -z "$GITHUB_TOKEN" || composer config -g github-oauth.github.com "$GITHUB_TOKEN"

# Get all tags of git repo
- git fetch origin 'refs/tags/*:refs/tags/*'

install:
# Install composer packages
- composer install

before_script:
# Generate codecept build classes
- php bin/codecept build

script:
# Run tests
- php bin/codecept run

after_success:
# Bump version
- test "$TRAVIS_BRANCH" != 'master' -o "$TRAVIS_PULL_REQUEST" != "false" || test -n "$(git tag --contains)" || bin/bump-version
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Legal Things

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
105 changes: 105 additions & 0 deletions README.md
@@ -0,0 +1,105 @@
Legal Things - CloudWatch Logger PHP
==================

This library provides you with a simplified interface to log data to AWS CloudWatch.


## Requirements

- [PHP](http://www.php.net) >= 5.5.0

_Required PHP extensions are marked by composer_


## Installation

The library can be installed using composer.

composer require legalthings/cloudwatch-logger-php

## Output

![output](https://user-images.githubusercontent.com/5793511/29072119-c16b1ce2-7c46-11e7-87e1-bde855aa279e.png)


## Usage

```php
use LegalThings/CloudWatchLogger;

$config = [
'aws' => [
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => [
'key' => 'my_key',
'secret' => 'my_secret'
]
],
'group_name' => 'group_name',
'instance_name' => 'instance_name',
'channel_name' => 'channel_name'
];

$logger = new CloudWatchLogger($config);

$logger->info('test_info', ['hello' => 'world']);
/*
outputs within the group 'group_name' and instance 'instance_name' on CloudWatch:

[2017-08-08 13:23:44] channel_name.INFO: my_notice
{
"hello": "world"
}
*/

$logger->notice('test_notice', ['foo' => 'bar']);
$logger->warn('test_warn', ['flag' => true]);
$logger->error('test_error', ['line' => 111]);
$logger->debug('test_debug', ['debugging' => false]);
```


## Configuration

```php
[
// required
'aws' => [
// required
'version' => 'latest',

// required
'region' => 'eu-west-1',

// optional, credentials may be omitted if using aws environment variables or roles
'credentials' => [
'key' => 'my_key',
'secret' => 'my_secret'
]
],

// required
'group_name' => 'group_name',

// required
'instance_name' => 'instance_name',

// optional
'channel_name' => 'channel_name',

// optional, defaults to 90
'retention_days' => 3,

// optional, defaults to 10000 and may not be greater than 10000
'batch_size' => 5000,

// optional
'tags' => [
'application' => 'php-test-app-1'
],

// optional, defaults to '[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n'
'format' => '[%datetime%] %message% %context%\n'
]
```
14 changes: 14 additions & 0 deletions bin/bump-version
@@ -0,0 +1,14 @@
#!/bin/bash

# Bump the patch version (http://semver.org/), tag and push

VERSION=$(php -r '$settings = json_decode(file_get_contents("composer.json")); echo $settings->version;')
PATCH_VERSION=$(git tag | grep v$VERSION | sort -r -V | head -n 1 | awk -F . '{print $3}')
test -n "$PATCH_VERSION" || PATCH_VERSION=-1;
let PATCH_VERSION++
sed -i 's/"version"\s*:\s*"'${VERSION}'"/"version": "'${VERSION}.${PATCH_VERSION}'"/' composer.json
git add composer.json
git commit -m "Bump version to v${VERSION}.${PATCH_VERSION}"
git tag "v${VERSION}.${PATCH_VERSION}"
git push origin "v${VERSION}.${PATCH_VERSION}"

21 changes: 21 additions & 0 deletions codeception.yml
@@ -0,0 +1,21 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
20 changes: 20 additions & 0 deletions composer.json
@@ -0,0 +1,20 @@
{
"name": "legalthings/cloudwatch-logger-php",
"description": "CloudWatch logger for PHP",
"version": "1.0.0",
"license": "MIT",
"require": {
"php": ">=5.5.0",
"aws/aws-sdk-php": "^3.12",
"maxbanton/cwh": "^1.0",
"monolog/monolog": "1.*"
},
"require-dev": {
"legalthings/php-code-quality": "^0.1.2"
},
"autoload": {
"psr-4": {
"LegalThings\\": "src/"
}
}
}

0 comments on commit 122b8ca

Please sign in to comment.