diff --git a/src/Client.php b/src/Client.php index d2e5b65..91bf05a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,6 +4,8 @@ namespace JsonRpc; use GuzzleHttp\Exception\ServerException; use JsonRpc\Exception\RpcServerException; +use JsonRpc\Logging\LogstashFormatter; +use Monolog\Handler\StreamHandler; use Monolog\Logger; class Client @@ -23,7 +25,10 @@ class Client $default = [ 'app' => '***', ]; - + $stream = new StreamHandler(app()->storagePath()."/logs/rpc_monitor_".date("Ymd").".log"); + $stream->setFormatter(new LogstashFormatter()); + $logger = new Logger('RPC.LOGGER'); + $logger->pushHandler($stream); $this->config = array_merge($default, $config); $this->id = 0; $this->logger = $logger; diff --git a/src/Providers/ClientServiceProvider.php b/src/Providers/ClientServiceProvider.php index a2b52c9..8560b48 100644 --- a/src/Providers/ClientServiceProvider.php +++ b/src/Providers/ClientServiceProvider.php @@ -4,10 +4,7 @@ namespace JsonRpc\Providers; use Illuminate\Support\ServiceProvider; use JsonRpc\Client; -use JsonRpc\Logging\LogstashFormatter; -use Monolog\Formatter\LineFormatter; -use Monolog\Handler\StreamHandler; -use Monolog\Logger; + class ClientServiceProvider extends ServiceProvider { @@ -21,12 +18,9 @@ class ClientServiceProvider extends ServiceProvider $this->app->configure('rpc'); $config = config('rpc.client'); - $stream = new StreamHandler($this->app->storagePath()."/logs/rpc_monitor_".date("Ymd").".log"); - $stream->setFormatter(new LogstashFormatter()); - $logger = new Logger('RPC.LOGGER'); - $logger->pushHandler($stream); - $this->app->singleton('rpc', function () use ($config, $logger) { - return new Client($config, $logger); + + $this->app->singleton('rpc', function () use ($config) { + return new Client($config); }); foreach ($config as $k => $item) { diff --git a/src/Server/JsonRpcTool.php b/src/Server/JsonRpcTool.php index 2c2fb17..d85760a 100644 --- a/src/Server/JsonRpcTool.php +++ b/src/Server/JsonRpcTool.php @@ -5,6 +5,7 @@ namespace JsonRpc\Server; use Illuminate\Http\Request; use Illuminate\View\Factory; use JsonRpc\Exception\RpcServerException; +use Monolog\Logger; /** * Class JsonRpcTool @@ -40,7 +41,7 @@ class JsonRpcTool $method = $request->input('method'); try { - $result = app('rpc.auth')->call($method, $params); + $result = app('rpc.'.$this->config['name'])->call($method, $params); $view->share('result', json_encode($result, JSON_PRETTY_PRINT)); } catch (RpcServerException $exception) { $view->share('error', ['code' => $exception->getCode(), 'message' => $exception->getMessage()]);