diff --git a/src/Client.php b/src/Client.php index 6f9b765..3350c9a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,18 +4,21 @@ namespace JsonRpc; use GuzzleHttp\Exception\ServerException; use JsonRpc\Exception\RpcServerException; +use Monolog\Logger; class Client { protected $config; protected $id; + + protected $logger; /** * @var \GuzzleHttp\Client */ protected $http; - public function __construct($config) + public function __construct($config, Logger $logger) { $default = [ 'app' => '***', @@ -23,6 +26,7 @@ class Client $this->config = array_merge($default, $config); $this->id = 0; + $this->logger = $logger; } public function endpoint($k) @@ -90,6 +94,7 @@ class Client if (isset($body['error']) && isset($body['error']['code']) && isset($body['error']['message'])) { throw new RpcServerException($body['error']['message'], $body['error']['code']); } + $this->logger->info('this is a test call log'); return $body['result']; } catch (\InvalidArgumentException $e) { diff --git a/src/Providers/ClientServiceProvider.php b/src/Providers/ClientServiceProvider.php index c76530b..29a2d35 100644 --- a/src/Providers/ClientServiceProvider.php +++ b/src/Providers/ClientServiceProvider.php @@ -19,8 +19,8 @@ class ClientServiceProvider extends ServiceProvider $this->app->configure('rpc'); $config = config('rpc.client'); -// $logger = new Logger('rpc-client-logger'); -// $logger->pushHandler(new StreamHandler($this->app->storagePath()."/logs/rpc_client_".date("Ymd").".log")); + $logger = new Logger('rpc-client-logger'); + $logger->pushHandler(new StreamHandler($this->app->storagePath()."/logs/rpc_client_".date("Ymd").".log")); $this->app->singleton('rpc', function () use ($config) { return new Client($config); });