This commit is contained in:
dongwei 2019-01-11 15:05:38 +08:00
parent 24750ed0f1
commit 25c6835a11
3 changed files with 12 additions and 12 deletions

View File

@ -4,6 +4,8 @@ namespace JsonRpc;
use GuzzleHttp\Exception\ServerException; use GuzzleHttp\Exception\ServerException;
use JsonRpc\Exception\RpcServerException; use JsonRpc\Exception\RpcServerException;
use JsonRpc\Logging\LogstashFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger; use Monolog\Logger;
class Client class Client
@ -23,7 +25,10 @@ class Client
$default = [ $default = [
'app' => '***', '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->config = array_merge($default, $config);
$this->id = 0; $this->id = 0;
$this->logger = $logger; $this->logger = $logger;

View File

@ -4,10 +4,7 @@ namespace JsonRpc\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use JsonRpc\Client; use JsonRpc\Client;
use JsonRpc\Logging\LogstashFormatter;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class ClientServiceProvider extends ServiceProvider class ClientServiceProvider extends ServiceProvider
{ {
@ -21,12 +18,9 @@ class ClientServiceProvider extends ServiceProvider
$this->app->configure('rpc'); $this->app->configure('rpc');
$config = config('rpc.client'); $config = config('rpc.client');
$stream = new StreamHandler($this->app->storagePath()."/logs/rpc_monitor_".date("Ymd").".log");
$stream->setFormatter(new LogstashFormatter()); $this->app->singleton('rpc', function () use ($config) {
$logger = new Logger('RPC.LOGGER'); return new Client($config);
$logger->pushHandler($stream);
$this->app->singleton('rpc', function () use ($config, $logger) {
return new Client($config, $logger);
}); });
foreach ($config as $k => $item) { foreach ($config as $k => $item) {

View File

@ -5,6 +5,7 @@ namespace JsonRpc\Server;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\View\Factory; use Illuminate\View\Factory;
use JsonRpc\Exception\RpcServerException; use JsonRpc\Exception\RpcServerException;
use Monolog\Logger;
/** /**
* Class JsonRpcTool * Class JsonRpcTool
@ -40,7 +41,7 @@ class JsonRpcTool
$method = $request->input('method'); $method = $request->input('method');
try { 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)); $view->share('result', json_encode($result, JSON_PRETTY_PRINT));
} catch (RpcServerException $exception) { } catch (RpcServerException $exception) {
$view->share('error', ['code' => $exception->getCode(), 'message' => $exception->getMessage()]); $view->share('error', ['code' => $exception->getCode(), 'message' => $exception->getMessage()]);