Commit 4ea56624 authored by Armando Lüscher's avatar Armando Lüscher

Introduce temporary output debug stream logging.

It's now possible to log all temporary PHP output to the debug log.
parent 98f83262
......@@ -169,7 +169,7 @@ class Request
*/
public static function execute($action, array $data = null)
{
$debug_handle = (TelegramLog::isDebugLogActive()) ? fopen('php://temp', 'w+') : false;
$debug_handle = TelegramLog::getDebugLogTempStream();
try {
$response = self::$client->post(
......@@ -180,14 +180,7 @@ class Request
throw new TelegramException($e->getMessage());
} finally {
//Logging verbose debug output
if ($debug_handle !== false) {
rewind($debug_handle);
TelegramLog::debug(sprintf(
"Verbose HTTP Request output:\n%s\n",
stream_get_contents($debug_handle)
));
fclose($debug_handle);
}
TelegramLog::endDebugLogTempStream("Verbose HTTP Request output:\n%s\n");
}
$result = $response->getBody();
......@@ -219,7 +212,7 @@ class Request
throw new TelegramException('Directory ' . $dirname . ' can\'t be created');
}
$debug_handle = (TelegramLog::isDebugLogActive()) ? fopen('php://temp', 'w+') : false;
$debug_handle = TelegramLog::getDebugLogTempStream();
try {
$response = self::$client->get(
......@@ -230,14 +223,7 @@ class Request
throw new TelegramException($e->getMessage());
} finally {
//Logging verbose debug output
if ($debug_handle !== false) {
rewind($debug_handle);
TelegramLog::debug(sprintf(
"Verbose HTTP File Download Request output:\n%s\n",
stream_get_contents($debug_handle)
));
fclose($debug_handle);
}
TelegramLog::endDebugLogTempStream("Verbose HTTP File Download Request output:\n%s\n");
}
return (filesize($loc_path) > 0);
......
......@@ -55,6 +55,13 @@ class TelegramLog
*/
static protected $update_log_path = null;
/**
* Temporary stream handle for debug log
*
* @var null
*/
static protected $debug_log_temp_stream_handle = null;
/**
* Initialize
*
......@@ -120,6 +127,41 @@ class TelegramLog
return self::$monolog->pushHandler(new StreamHandler(self::$debug_log_path, Logger::DEBUG));
}
/**
* Get the stream handle of the temporary debug output
*
* @return mixed The stream if debug is active, else false
*/
public static function getDebugLogTempStream()
{
if (self::$debug_log_temp_stream_handle === null) {
if (self::isDebugLogActive()) {
self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+');
} else {
return false;
}
}
return self::$debug_log_temp_stream_handle;
}
/**
* Write the temporary debug stream to log and close the stream handle
*
* @param string $message Message (with placeholder) to write to the debug log
*/
public static function endDebugLogTempStream($message = '%s')
{
if (self::$debug_log_temp_stream_handle !== null) {
rewind(self::$debug_log_temp_stream_handle);
self::debug(sprintf(
$message,
stream_get_contents(self::$debug_log_temp_stream_handle)
));
fclose(self::$debug_log_temp_stream_handle);
self::$debug_log_temp_stream_handle = null;
}
}
/**
* Initialize update log
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment