Add support to dump debug output to a log file
This commit is contained in:
parent
16f0bd4966
commit
d6c65bec9d
@ -140,3 +140,5 @@ Actually, the following constants can be overrided:
|
||||
- `HTTP_TIMEOUT` => default value is 10 seconds
|
||||
- `APP_VERSION` => default value is master
|
||||
- `DB_FILENAME` => default value is `data/db.sqlite`
|
||||
- `DEBUG` => default is false (enable logs dump of picoFeed)
|
||||
- `DEBUG_DIRECTORY` => default is /tmp (place to store log files)
|
@ -14,6 +14,8 @@ if (file_exists('config.php')) require 'config.php';
|
||||
defined('APP_VERSION') or define('APP_VERSION', 'master');
|
||||
defined('HTTP_TIMEOUT') or define('HTTP_TIMEOUT', 10);
|
||||
defined('DB_FILENAME') or define('DB_FILENAME', 'data/db.sqlite');
|
||||
defined('DEBUG') or define('DEBUG', false);
|
||||
defined('DEBUG_DIRECTORY') or define('DEBUG_DIRECTORY', '/tmp');
|
||||
|
||||
PicoTools\container('db', function() {
|
||||
|
||||
|
@ -26,3 +26,4 @@ if ($update_interval !== null && $call_interval !== null && $limit === Model\LIM
|
||||
}
|
||||
|
||||
Model\update_feeds($limit);
|
||||
Model\write_debug();
|
||||
|
17
index.php
17
index.php
@ -284,7 +284,7 @@ Router\get_action('refresh-feed', function() {
|
||||
|
||||
$id = Request\int_param('feed_id');
|
||||
if ($id) Model\update_feed($id);
|
||||
|
||||
Model\write_debug();
|
||||
Response\redirect('?action=unread');
|
||||
});
|
||||
|
||||
@ -292,13 +292,15 @@ Router\get_action('refresh-feed', function() {
|
||||
// Ajax call to refresh one feed
|
||||
Router\post_action('refresh-feed', function() {
|
||||
|
||||
$id = Request\int_param('feed_id');
|
||||
$id = Request\int_param('feed_id', 0);
|
||||
|
||||
if ($id) {
|
||||
Response\json(array('feed_id' => $id, 'result' => Model\update_feed($id)));
|
||||
|
||||
$result = Model\update_feed($id);
|
||||
Model\write_debug();
|
||||
}
|
||||
|
||||
Response\json(array('feed_id' => 0, 'result' => false));
|
||||
Response\json(array('feed_id' => $id, 'result' => $result));
|
||||
});
|
||||
|
||||
|
||||
@ -332,6 +334,8 @@ Router\get_action('flush-history', function() {
|
||||
Router\get_action('refresh-all', function() {
|
||||
|
||||
Model\update_feeds();
|
||||
Model\write_debug();
|
||||
|
||||
Session\flash(t('Your subscriptions are updated'));
|
||||
Response\redirect('?action=unread');
|
||||
});
|
||||
@ -364,7 +368,10 @@ Router\get_action('add', function() {
|
||||
// Add the feed
|
||||
Router\post_action('add', function() {
|
||||
|
||||
if (Model\import_feed($_POST['url'])) {
|
||||
$result = Model\import_feed($_POST['url']);
|
||||
Model\write_debug();
|
||||
|
||||
if ($result) {
|
||||
|
||||
Session\flash(t('Subscription added successfully.'));
|
||||
Response\redirect('?action=feeds');
|
||||
|
13
model.php
13
model.php
@ -61,6 +61,19 @@ function get_paging_options()
|
||||
}
|
||||
|
||||
|
||||
function write_debug()
|
||||
{
|
||||
if (DEBUG) {
|
||||
|
||||
file_put_contents(
|
||||
DEBUG_DIRECTORY.'/miniflux_'.date('YmdH').'.debug',
|
||||
var_export(\PicoFeed\Logging::$messages, true).PHP_EOL,
|
||||
FILE_APPEND | LOCK_EX
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function encode_item_id($input)
|
||||
{
|
||||
return strtr(base64_encode($input), '+/=', '-_,');
|
||||
|
13
vendor/PicoFeed/Logging.php
vendored
Normal file
13
vendor/PicoFeed/Logging.php
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace PicoFeed;
|
||||
|
||||
class Logging
|
||||
{
|
||||
public static $messages = array();
|
||||
|
||||
public static function log($message)
|
||||
{
|
||||
self::$messages[] = $message;
|
||||
}
|
||||
}
|
10
vendor/PicoFeed/Parser.php
vendored
10
vendor/PicoFeed/Parser.php
vendored
@ -2,6 +2,7 @@
|
||||
|
||||
namespace PicoFeed;
|
||||
|
||||
require_once __DIR__.'/Logging.php';
|
||||
require_once __DIR__.'/Filter.php';
|
||||
require_once __DIR__.'/Encoding.php';
|
||||
|
||||
@ -14,7 +15,6 @@ abstract class Parser
|
||||
public $title = '';
|
||||
public $updated = '';
|
||||
public $items = array();
|
||||
public $debug = false;
|
||||
|
||||
|
||||
abstract public function execute();
|
||||
@ -47,17 +47,21 @@ abstract class Parser
|
||||
}
|
||||
|
||||
|
||||
public function displayXmlErrors()
|
||||
public function getXmlErrors()
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
foreach(\libxml_get_errors() as $error) {
|
||||
|
||||
printf("Message: %s\nLine: %d\nColumn: %d\nCode: %d\n",
|
||||
$errors[] = sprintf('XML error: %s (Line: %d - Column: %d - Code: %d)',
|
||||
$error->message,
|
||||
$error->line,
|
||||
$error->column,
|
||||
$error->code
|
||||
);
|
||||
}
|
||||
|
||||
return implode(', ', $errors);
|
||||
}
|
||||
|
||||
|
||||
|
2
vendor/PicoFeed/Parsers/Atom.php
vendored
2
vendor/PicoFeed/Parsers/Atom.php
vendored
@ -11,7 +11,7 @@ class Atom extends \PicoFeed\Parser
|
||||
|
||||
if ($xml === false) {
|
||||
|
||||
if ($this->debug) $this->displayXmlErrors();
|
||||
\PicoFeed\Logging::log($this->getXmlErrors());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
2
vendor/PicoFeed/Parsers/Rss10.php
vendored
2
vendor/PicoFeed/Parsers/Rss10.php
vendored
@ -11,7 +11,7 @@ class Rss10 extends \PicoFeed\Parser
|
||||
|
||||
if ($xml === false) {
|
||||
|
||||
if ($this->debug) $this->displayXmlErrors();
|
||||
\PicoFeed\Logging::log($this->getXmlErrors());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
2
vendor/PicoFeed/Parsers/Rss20.php
vendored
2
vendor/PicoFeed/Parsers/Rss20.php
vendored
@ -11,7 +11,7 @@ class Rss20 extends \PicoFeed\Parser
|
||||
|
||||
if ($xml === false) {
|
||||
|
||||
if ($this->debug) $this->displayXmlErrors();
|
||||
\PicoFeed\Logging::log($this->getXmlErrors());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
13
vendor/PicoFeed/Reader.php
vendored
13
vendor/PicoFeed/Reader.php
vendored
@ -2,6 +2,7 @@
|
||||
|
||||
namespace PicoFeed;
|
||||
|
||||
require_once __DIR__.'/Logging.php';
|
||||
require_once __DIR__.'/Parser.php';
|
||||
require_once __DIR__.'/RemoteResource.php';
|
||||
|
||||
@ -83,29 +84,39 @@ class Reader
|
||||
|
||||
if (strpos($first_tag, '<feed') !== false) {
|
||||
|
||||
Logging::log('Reader: discover Atom feed');
|
||||
|
||||
require_once __DIR__.'/Parsers/Atom.php';
|
||||
return new Parsers\Atom($this->content);
|
||||
}
|
||||
else if (strpos($first_tag, '<rss') !== false &&
|
||||
(strpos($first_tag, 'version="2.0"') !== false || strpos($first_tag, 'version=\'2.0\'') !== false)) {
|
||||
|
||||
Logging::log('Reader: discover RSS 2.0 feed');
|
||||
|
||||
require_once __DIR__.'/Parsers/Rss20.php';
|
||||
return new Parsers\Rss20($this->content);
|
||||
}
|
||||
else if (strpos($first_tag, '<rss') !== false &&
|
||||
(strpos($first_tag, 'version="0.92"') !== false || strpos($first_tag, 'version=\'0.92\'') !== false)) {
|
||||
|
||||
Logging::log('Reader: discover RSS 0.92 feed');
|
||||
|
||||
require_once __DIR__.'/Parsers/Rss92.php';
|
||||
return new Parsers\Rss92($this->content);
|
||||
}
|
||||
else if (strpos($first_tag, '<rss') !== false &&
|
||||
(strpos($first_tag, 'version="0.91"') !== false || strpos($first_tag, 'version=\'0.91\'') !== false)) {
|
||||
|
||||
Logging::log('Reader: discover RSS 0.91 feed');
|
||||
|
||||
require_once __DIR__.'/Parsers/Rss91.php';
|
||||
return new Parsers\Rss91($this->content);
|
||||
}
|
||||
else if (strpos($first_tag, '<rdf:') !== false && strpos($first_tag, 'xmlns="http://purl.org/rss/1.0/"') !== false) {
|
||||
|
||||
Logging::log('Reader: discover RSS 1.0 feed');
|
||||
|
||||
require_once __DIR__.'/Parsers/Rss10.php';
|
||||
return new Parsers\Rss10($this->content);
|
||||
}
|
||||
@ -129,6 +140,8 @@ class Reader
|
||||
return false;
|
||||
}
|
||||
|
||||
Logging::log('Reader: run discover()');
|
||||
|
||||
\libxml_use_internal_errors(true);
|
||||
|
||||
$dom = new \DOMDocument;
|
||||
|
36
vendor/PicoFeed/RemoteResource.php
vendored
36
vendor/PicoFeed/RemoteResource.php
vendored
@ -2,6 +2,8 @@
|
||||
|
||||
namespace PicoFeed;
|
||||
|
||||
require_once __DIR__.'/Logging.php';
|
||||
|
||||
class RemoteResource
|
||||
{
|
||||
public $user_agent;
|
||||
@ -69,7 +71,7 @@ class RemoteResource
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$response = $this->makeRequest();
|
||||
$response = $this->doRequest();
|
||||
|
||||
$this->etag = isset($response['headers']['ETag']) ? $response['headers']['ETag'] : '';
|
||||
$this->last_modified = isset($response['headers']['Last-Modified']) ? $response['headers']['Last-Modified'] : '';
|
||||
@ -98,7 +100,7 @@ class RemoteResource
|
||||
}
|
||||
|
||||
|
||||
public function makeRequest()
|
||||
public function doRequest()
|
||||
{
|
||||
$http_code = 200;
|
||||
$http_body = '';
|
||||
@ -110,6 +112,10 @@ class RemoteResource
|
||||
}
|
||||
else {
|
||||
|
||||
Logging::log('Fetch URL: '.$this->url);
|
||||
Logging::log('Etag: '.$this->etag);
|
||||
Logging::log('Last-Modified: '.$this->last_modified);
|
||||
|
||||
$headers = array('Connection: close');
|
||||
|
||||
if ($this->etag) $headers[] = 'If-None-Match: '.$this->etag;
|
||||
@ -131,6 +137,25 @@ class RemoteResource
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
$http_response = curl_exec($ch);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
|
||||
Logging::log('cURL error: '.curl_error($ch));
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return array(
|
||||
'status' => $http_code,
|
||||
'body' => $http_body,
|
||||
'headers' => $http_headers
|
||||
);
|
||||
}
|
||||
|
||||
Logging::log('cURL total time: '.curl_getinfo($ch, CURLINFO_TOTAL_TIME));
|
||||
Logging::log('cURL dns lookup time: '.curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME));
|
||||
Logging::log('cURL connect time: '.curl_getinfo($ch, CURLINFO_CONNECT_TIME));
|
||||
Logging::log('cURL speed download: '.curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD));
|
||||
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$http_body = '';
|
||||
$http_headers = array();
|
||||
@ -162,6 +187,13 @@ class RemoteResource
|
||||
$http_body = implode("\r\n", array_splice($lines, $i + 1));
|
||||
}
|
||||
|
||||
Logging::log('HTTP status code: '.$http_code);
|
||||
|
||||
foreach ($http_headers as $header_name => $header_value) {
|
||||
|
||||
Logging::log('HTTP headers: '.$header_name.' => '.$header_value);
|
||||
}
|
||||
|
||||
return array(
|
||||
'status' => $http_code,
|
||||
'body' => $http_body,
|
||||
|
Loading…
Reference in New Issue
Block a user