Answer the question
In order to leave comments, you need to log in
How to make Guzzle logging work in Laravel?
Hello everyone, there is such a situation - an application on Laravel 4.2, I put gasl 6.0 into it.
I tried to do it through Middleware, but nothing happens:
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
$stack = HandlerStack::create();
$stack->push(
Middleware::log(
new Logger('Logger'),
new MessageFormatter('{req_body} - {res_body}')
)
);
$client = new \GuzzleHttp\Client(
[
'base_uri' => 'some-url.com',
'handler' => $stack,
]
);
Answer the question
In order to leave comments, you need to log in
If you need to write a Guzzle log file to the general log, then:
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
$stack = HandlerStack::create();
$stack->push(
Middleware::log(
\Illuminate\Support\Facades\Log::getMonolog(),
new MessageFormatter('{req_body} - {res_body}')
)
);
$client = new \GuzzleHttp\Client(
[
'base_uri' => 'some-url.com',
'handler' => $stack,
]
);
use Monolog\Handler\StreamHandler;
// ....
$logger = new Logger('GuzzleLogger');
$logger->pushHandler(new StreamHandler(storage_path('logs/guzzle.log')));
$stack->push(
Middleware::log(
$logger,
new MessageFormatter('{req_body} - {res_body}')
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question