]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add logger to FileCookieJar 4063/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 24 Jul 2019 14:07:38 +0000 (16:07 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 24 Jul 2019 14:07:38 +0000 (16:07 +0200)
src/Wallabag/CoreBundle/Helper/FileCookieJar.php
src/Wallabag/CoreBundle/Resources/config/services.yml

index 52c7f5deb6aa080ddf56806e1cf006e91205897c..9a63e9493259b45f8c7b4bc0771661c713936948 100644 (file)
@@ -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 = '';
         }
index 169b67e5c17e0f853b81348990af5d437ab3915b..3f3d4de7124dacf376063daf59d626c285776e29 100644 (file)
@@ -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