From f1d4923ebe0479ce91f982d7949b9e8322ce41b0 Mon Sep 17 00:00:00 2001 From: Lukas Rademacher Date: Fri, 30 Jun 2017 22:34:23 +0200 Subject: [PATCH] added psr-3 logger support --- composer.json | 6 ++- composer.lock | 132 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/FSAPI.php | 18 +++++++ src/Radio.php | 21 +++++++- 4 files changed, 171 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 59e6ab2..c2fc9d5 100644 --- a/composer.json +++ b/composer.json @@ -9,11 +9,13 @@ }, "require": { "php": ">=5.3.0", - "ext-curl": "*" + "ext-curl": "*", + "psr/log": "*" }, "require-dev": { "phpunit/phpunit": "*", - "jakub-onderka/php-parallel-lint": "^0.9.2" + "jakub-onderka/php-parallel-lint": "^0.9.2", + "monolog/monolog": "*" }, "scripts": { "phpunit": "vendor/bin/phpunit --testsuite all", diff --git a/composer.lock b/composer.lock index d413657..42a5771 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,57 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a558012e0ea853cda2bad365d75ee5e2", - "content-hash": "da5d4005eab4668c55864604db1f228f", - "packages": [], + "hash": "9ff555d0b1eb91885daa1c852bfef9d1", + "content-hash": "a0b3a8e9044c989532c6b909106bf8a3", + "packages": [ + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10 12:19:37" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -109,6 +157,84 @@ "homepage": "https://github.com/JakubOnderka/PHP-Parallel-Lint", "time": "2015-12-15 10:42:16" }, + { + "name": "monolog/monolog", + "version": "1.23.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "provide": { + "psr/log-implementation": "1.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^2.4.9 || ^3.0", + "doctrine/couchdb": "~1.0@dev", + "graylog2/gelf-php": "~1.0", + "jakub-onderka/php-parallel-lint": "0.9", + "php-amqplib/php-amqplib": "~2.4", + "php-console/php-console": "^3.1.3", + "phpunit/phpunit": "~4.5", + "phpunit/phpunit-mock-objects": "2.3.0", + "ruflin/elastica": ">=0.90 <3.0", + "sentry/sentry": "^0.13", + "swiftmailer/swiftmailer": "^5.3|^6.0" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-mongo": "Allow sending log messages to a MongoDB server", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "php-console/php-console": "Allow sending log messages to Google Chrome", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "sentry/sentry": "Allow sending log messages to a Sentry server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "http://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "time": "2017-06-19 01:22:40" + }, { "name": "myclabs/deep-copy", "version": "1.6.1", diff --git a/src/FSAPI.php b/src/FSAPI.php index 210c8b0..eab57fd 100644 --- a/src/FSAPI.php +++ b/src/FSAPI.php @@ -7,12 +7,18 @@ use FSAPI\Request\Requests; use FSAPI\Request\Request; use FSAPI\Nodes\NodesFactory; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; class FSAPI implements Requests { protected $call_method_whitelist = array('CREATE_SESSION','DELETE_SESSION','GET_NOTIFIES'); protected $Request = null; + /** + * @var LoggerInterface + */ + private $logger; /** * create a new FSAPI-Object @@ -24,9 +30,21 @@ class FSAPI implements Requests public function __construct(Request $Request) { $this->Request = $Request; + $this->logger = new NullLogger(); } + /** + * Set a PSR-3 Logger + * @param LoggerInterface $logger + */ + public function setLogger($logger){ + if(method_exists($logger,'withName')){ + $logger = $logger->withName('FSAPI'); + } + $this->logger = $logger; + } + /** * Do the request-call via the Request Object * diff --git a/src/Radio.php b/src/Radio.php index 7c3c15e..f45d846 100644 --- a/src/Radio.php +++ b/src/Radio.php @@ -5,6 +5,8 @@ use FSAPI\Request\Request; use FSAPI\Nodes\NodesFactory; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; class Radio{ @@ -12,6 +14,10 @@ class Radio{ protected $host = null; protected $pin = null; protected $sid = null; + /** + * @var LoggerInterface + */ + private $logger = null; protected $lists = array(); @@ -23,7 +29,6 @@ class Radio{ protected $api_level = null; public function __construct($host,$pin){ - $this->host = $host; $this->pin = $pin; $this->Request = new Request($this->host,null,$this->pin); @@ -31,6 +36,20 @@ public function __construct($host,$pin){ $this->sid = $this->fsapi->doRequest('CREATE_SESSION'); $this->Request->setSID($this->sid); $this->api_level = 1; + $this->logger = new NullLogger(); + } + + + /** + * Set a PSR-3 Logger + * @param LoggerInterface $logger + */ + public function setLogger($logger){ + if(method_exists($logger,'withName')){ + $logger = $logger->withName('Radio'); + } + $this->logger = $logger; + $this->fsapi->setLogger($logger); }