mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 21:56:31 +02:00
Added support for retry logic
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Monolog package.
|
* This file is part of the Monolog package.
|
||||||
*
|
*
|
||||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
@@ -15,12 +15,12 @@ use Monolog\Logger;
|
|||||||
use Monolog\Formatter\LogglyFormatter;
|
use Monolog\Formatter\LogglyFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends errors to Loggly.
|
* Sends errors to Loggly.
|
||||||
*
|
*
|
||||||
* @author Przemek Sobstel <przemek@sobstel.org>
|
* @author Przemek Sobstel <przemek@sobstel.org>
|
||||||
* @author Adam Pancutt <adam@pancutt.com>
|
* @author Adam Pancutt <adam@pancutt.com>
|
||||||
* @author Gregory Barchard <gregory@barchard.net>
|
* @author Gregory Barchard <gregory@barchard.net>
|
||||||
*/
|
*/
|
||||||
class LogglyHandler extends AbstractProcessingHandler
|
class LogglyHandler extends AbstractProcessingHandler
|
||||||
{
|
{
|
||||||
const HOST = 'logs-01.loggly.com';
|
const HOST = 'logs-01.loggly.com';
|
||||||
@@ -92,11 +92,45 @@ class LogglyHandler extends AbstractProcessingHandler
|
|||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
if (curl_exec($ch) === false) {
|
$RETRY_COUNT = 5;
|
||||||
throw new \RuntimeException(sprintf('Curl error (code %s): %s', curl_errno($ch), curl_error($ch)));
|
$TOTAL_RETRIES = 0;
|
||||||
}
|
|
||||||
|
|
||||||
curl_close($ch);
|
/*
|
||||||
|
* Curl error code 6 : CURLE_COULDNT_RESOLVE_HOST
|
||||||
|
* Curl error code 7 : CURLE_COULDNT_CONNECT
|
||||||
|
* Curl error code 9 : CURLE_REMOTE_ACCESS_DENIED
|
||||||
|
* Curl error code 22 : CURLE_HTTP_RETURNED_ERROR
|
||||||
|
* Curl error code 25 : CURLE_UPLOAD_FAILED
|
||||||
|
* Curl error code 26 : CURLE_READ_ERROR
|
||||||
|
* Curl error code 28 : CURLE_OPERATION_TIMEDOUT
|
||||||
|
* Curl error code 34 : CURLE_HTTP_POST_ERROR
|
||||||
|
* Curl error code 35 : CURLE_SSL_CONNECT_ERROR
|
||||||
|
*
|
||||||
|
* Curl Error Codes : http://curl.haxx.se/libcurl/c/libcurl-errors.html
|
||||||
|
*/
|
||||||
|
$CurlErrorCodesForRetries = array(6,7,9,22,25,26,28,34,35);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
$TOTAL_RETRIES = $TOTAL_RETRIES + 1;
|
||||||
|
if (curl_exec($ch) === false) {
|
||||||
|
/*
|
||||||
|
If the error cannot be controlled by retries or
|
||||||
|
total retry count is already completed then
|
||||||
|
show error and break the loop
|
||||||
|
*/
|
||||||
|
if(in_array(curl_errno($ch),$CurlErrorCodesForRetries) === false
|
||||||
|
|| $TOTAL_RETRIES > $RETRY_COUNT){
|
||||||
|
echo sprintf('Curl error (code %s): %s', curl_errno($ch), curl_error($ch));
|
||||||
|
curl_close($ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
curl_close($ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}while($TOTAL_RETRIES <= $RETRY_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDefaultFormatter()
|
protected function getDefaultFormatter()
|
||||||
|
Reference in New Issue
Block a user