0

How can I see inside the $this object in my logger file using prs logger?

I tried this

\Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->info("in getMediaGalleryImages " .json_encode($this));

But this gives me {} every time.

[2019-05-29 10:07:24] report.INFO: in getMediaGalleryImages {} [] []

What's the right method to see inside the $this object in Magento 2 logger.

5
  • try $self instead of $this Commented May 29, 2019 at 10:20
  • But $this is used in the code $this->hasData('media_gallery_images'), not self
    – summu
    Commented May 29, 2019 at 10:20
  • Not sure but $self can do the trick. Commented May 29, 2019 at 10:21
  • why you need json_encode($this)?
    – Amit Bera
    Commented May 29, 2019 at 10:22
  • @AmitBera I am stuck in this issue so i am debugging it, you have any idea about this . magento.stackexchange.com/questions/276313/…
    – summu
    Commented May 29, 2019 at 10:23

1 Answer 1

0
  1. Use DependencyInjection instead of ObjectManager
  2. 2nd argument of any Logger message is Context - use it instead. Example:
$this->logger->warning('User cannot be logged in', ['username' => $user, 'ip' => $ip]);
  1. Use $this->getData() instead of just $this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.