Last active
March 19, 2016 20:09
-
-
Save korchasa/e771b42f4f14260eb914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param $log_name | |
* @param array $guzzle_options | |
* @return \GuzzleHttp\Client | |
*/ | |
function logging_guzzle($log_name, array $guzzle_options = []) | |
{ | |
$log_file = storage_path('logs/' . $log_name . '.log'); | |
$writer = new \Monolog\Handler\StreamHandler($log_file); | |
$writer->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true)); | |
$logger = new \Monolog\Logger($log_name); | |
$logger->pushHandler($writer); | |
$handler = \GuzzleHttp\HandlerStack::create(); | |
$handler->push(\GuzzleHttp\Middleware::log( | |
$logger, | |
new \GuzzleHttp\MessageFormatter(\GuzzleHttp\MessageFormatter::DEBUG) | |
)); | |
return new \GuzzleHttp\Client(array_merge(array( | |
'handler' => $handler, | |
'http_errors' => false, | |
), $guzzle_options)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment