stechstudio / piton
PSR-3 Compatible Splunk Storm Logging
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: 4.0.0
- psr/log: 1.0.0
Requires (Dev)
- evert/phpdoc-md: 0.0.*
- phpdocumentor/phpdocumentor: v2.7.0
- phpunit/phpunit: 4.2.*
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2023-02-27 17:52:36 UTC
README
The PSR-3 Compliant SplunkStorm Logger for PHP
Piton was developed in order to allow simple access to the SplunkStorm REST API from PHP code. While we use the SplunkStorm log shippers for the majority of our applications, we ran into cases of short lived tasks, running on short lived EC2 instances, that didn't warrant setting up log shipping.
However, we did desire the ability to capture the logs on SplunkStorm. Because the majority of these tasks run on Iron.io's IronWorker and are CLI based, we also desired the ability to log to the console. Thus, our logger ships with console and splunk appenders.
We also happen to think highly of the PHP FIG standards, and desire to meet them where possible. After writing the logger for ourselves, we decided others might want to leverage it to, and are releasing it into the wild.
Build Status | Code Coverage | |
---|---|---|
Master | ||
Develop |
Installation / Usage
-
Download the
composer.phar
executable or use the installer.$ curl -sS https://getcomposer.org/installer | php
-
Create a composer.json defining your dependencies. Note that this example is a short version for applications that are not meant to be published as packages themselves. To create libraries/packages please read the documentation.
{ "require": { "stechstudio/piton": ">=0.1.1" } }
-
Run Composer:
php composer.phar install
-
Browse for more packages on Packagist.
Documentations
Check out the docs/api directory.
Examples
Check out the examples directory.
Quickstart
You will need a SplunkStorm Project API Hostname, Project ID, and Access Token. You can find them in the data section of your SplunkStorm Project. Select Data, the API, and you will find everything you need.
$allAppenders = [ 'logger' => ['level' => 'info'], 'appenders' => [ 'console' => [ 'target' => 'STDOUT', 'class' => 'Piton\Appender\Console' ], 'null' => ['class' => 'Piton\Appender\Null'], 'splunk' => [ 'target' => 'api-fake.data.splunkstorm.com', 'class' => 'Piton\Appender\SplunkStorm', 'context' => [ 'SplunkStorm' => [ 'projectID' => 'SomeFakeProjectID', 'accessToken' => 'AnotherFakeAccessToken', 'apiVersion' => 1, 'apiEndpoint' => 'inputs/http', 'urlScheme' => 'https' ] ] ] ] ]; $logger = new Logger($allAppenders); $logger->setLevel('all'); $requireMessageFormat = '{TIMESTAMP} app="SimpleConsoleLogging" level="{LOGLEVEL}" file="{file}" line={line} class="{class}" msg="{MESSAGE}" '; $logger->setAndEnableRequiredMessage($requireMessageFormat, true); runLogMessages('Because we log to SplunkStorm, and we PWN our logs!', ['file'=>__FILE__,'class'=>__CLASS__, 'line'=>__LINE__]); function runLogMessages($message, $context = array()){ global $logger; $logger->fatal($message, $context); $logger->emergency($message, $context); $logger->alert($message, $context); $logger->critical($message, $context); $logger->error($message, $context); $logger->warning($message, $context); $logger->notice($message, $context); $logger->info($message, $context); $logger->debug($message, $context); $logger->trace($message, $context); }