From 25c6835a11d594ab3afd96cf2860ed0a73bf9e19 Mon Sep 17 00:00:00 2001 From: dongwei <838456736@qq.com> Date: Fri, 11 Jan 2019 15:05:38 +0800 Subject: [PATCH] logstash --- src/Client.php | 7 ++++++- src/Providers/ClientServiceProvider.php | 14 ++++---------- src/Server/JsonRpcTool.php | 3 ++- 3 files changed, 12 insertions(+), 12 deletions(-) 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()]);