From 51d7f62b316abfc14e770b3108edb0e3f48e38dd Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Jul 2019 16:07:38 +0200 Subject: Add logger to FileCookieJar --- src/Wallabag/CoreBundle/Helper/FileCookieJar.php | 19 +++++++++++++++++++ src/Wallabag/CoreBundle/Resources/config/services.yml | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Helper/FileCookieJar.php b/src/Wallabag/CoreBundle/Helper/FileCookieJar.php index 52c7f5de..9a63e949 100644 --- a/src/Wallabag/CoreBundle/Helper/FileCookieJar.php +++ b/src/Wallabag/CoreBundle/Helper/FileCookieJar.php @@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Helper; use GuzzleHttp\Cookie\FileCookieJar as BaseFileCookieJar; use GuzzleHttp\Cookie\SetCookie; use GuzzleHttp\Utils; +use Psr\Log\LoggerInterface; /** * Overidden Cookie behavior to: @@ -13,6 +14,19 @@ use GuzzleHttp\Utils; */ class FileCookieJar extends BaseFileCookieJar { + private $logger; + + /** + * @param LoggerInterface $logger Only used to log info when something goes wrong + * @param string $cookieFile File to store the cookie data + */ + public function __construct(LoggerInterface $logger, $cookieFile) + { + parent::__construct($cookieFile); + + $this->logger = $logger; + } + /** * Saves the cookies to a file. * @@ -57,6 +71,11 @@ class FileCookieJar extends BaseFileCookieJar try { $data = Utils::jsonDecode($json, true); } catch (\InvalidArgumentException $e) { + $this->logger->error('JSON inside the cookie is broken', [ + 'json' => $json, + 'error_msg' => $e->getMessage(), + ]); + // cookie file is invalid, just ignore the exception and it'll reset the whole cookie file $data = ''; } diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 169b67e5..3f3d4de7 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -83,7 +83,9 @@ services: wallabag_core.guzzle.cookie_jar: class: Wallabag\CoreBundle\Helper\FileCookieJar - arguments: ["%kernel.cache_dir%/cookiejar.json"] + arguments: + - "@logger" + - "%kernel.cache_dir%/cookiejar.json" wallabag_core.content_proxy: class: Wallabag\CoreBundle\Helper\ContentProxy -- cgit v1.2.3