From a2967cae91cf50f2753e7bee94695418a8519314 Mon Sep 17 00:00:00 2001 From: alphayax Date: Sun, 22 May 2016 16:34:32 +0200 Subject: [PATCH] Use Monolog --- composer.json | 3 ++- freebox/api/v3/services/login/Authorize.php | 13 +++++-------- freebox/utils/Application.php | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 6cce278..5bd2a7b 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ ], "require" : { "alphayax/php_utils" : "^0.1.1", - "php": ">=5.5.0" + "php": ">=5.5.0", + "monolog/monolog": "1.9.*" }, "autoload": { "psr-4": {"alphayax\\": "./"} diff --git a/freebox/api/v3/services/login/Authorize.php b/freebox/api/v3/services/login/Authorize.php index 35db33a..ca0d0f5 100644 --- a/freebox/api/v3/services/login/Authorize.php +++ b/freebox/api/v3/services/login/Authorize.php @@ -2,7 +2,6 @@ namespace alphayax\freebox\api\v3\services\login; use alphayax\freebox\api\v3\Service; use alphayax\freebox\utils\Application; -use alphayax\utils\cli\IO; /** * Class Authorize @@ -57,9 +56,9 @@ class Authorize extends Service { /// For verbose switch( $this->status){ - case self::STATUS_GRANTED : IO::stdout('Access granted !', 0, true, IO::COLOR_GREEN); break; - case self::STATUS_TIMEOUT : IO::stdout('Access denied. You take to long to authorize app', 0, true, IO::COLOR_RED); break; - case self::STATUS_DENIED : IO::stdout('Access denied. Freebox denied app connexion', 0, true, IO::COLOR_RED); break; + case self::STATUS_GRANTED : $this->application->getLogger()->addInfo( 'Access granted !'); break; + case self::STATUS_TIMEOUT : $this->application->getLogger()->addCritical( 'Access denied. You take to long to authorize app'); break; + case self::STATUS_DENIED : $this->application->getLogger()->addCritical( 'Access denied. Freebox denied app connexion'); break; } } } @@ -80,7 +79,7 @@ class Authorize extends Service { $response = $rest->getCurlResponse(); - IO::stdout( 'Authorization send to Freebox. Waiting for response...', 0, true, IO::COLOR_YELLOW); + $this->application->getLogger()->addInfo( 'Authorization send to Freebox. Waiting for response...'); $this->app_token = $response['result']['app_token']; $this->track_id = $response['result']['track_id']; @@ -90,8 +89,6 @@ class Authorize extends Service { * @throws \Exception */ public function get_authorization_status(){ - IO::stdout( 'Check authorization status... ', 0, false, IO::COLOR_YELLOW); - $rest = $this->getService( self::API_LOGIN_AUTHORIZE . $this->track_id); $rest->GET(); @@ -100,7 +97,7 @@ class Authorize extends Service { $this->status = $result['status']; $this->challenge = $result['challenge']; - IO::stdout( $this->status, 0, true, IO::COLOR_BLUE); + $this->application->getLogger()->addInfo( 'Freebox authorization status : '. $this->status); } /** diff --git a/freebox/utils/Application.php b/freebox/utils/Application.php index 931d85e..bbb40bd 100644 --- a/freebox/utils/Application.php +++ b/freebox/utils/Application.php @@ -1,6 +1,8 @@ id = $app_id; $this->name = $app_name; $this->version = $app_version; + /// Logger + $this->logger = new Logger('fbx_api_logger'); + $this->logger->pushHandler( new ErrorLogHandler()); } /** @@ -121,4 +129,11 @@ class Application { } } + /** + * @return Logger + */ + public function getLogger() { + return $this->logger; + } + }