logstash
This commit is contained in:
parent
24750ed0f1
commit
25c6835a11
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user