Book Image

Magento 2 Development Cookbook

Book Image

Magento 2 Development Cookbook

Overview of this book

With the challenges of growing an online business, Magento 2 is an open source e-commerce platform with innumerable functionalities that gives you the freedom to make on-the-fly decisions. It allows you to customize multiple levels of security permissions and enhance the look and feel of your website, and thus gives you a personalized experience in promoting your business.
Table of Contents (18 chapters)
Magento 2 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Logging into Magento 2


The standard debugging techniques in PHP are echo $variable, die($variable) and var_dump($variable). These simple debugging tricks don't always work (when you are working with AJAX and JSON) when it is printed in a hidden HTML section.

If you want to do a simple debugging trick without changing the HTML output of a page, you can use the Magento logging. This will write the debugged results to a log file.

Getting ready

We will print some data to the Magento log files. To easily view the content of these files, we need command line access. Also, open your IDE because we will add some logging statements in the Magento code.

How to do it...

Perform the following steps to describe how we can use logging in Magento 2:

  1. If we want to debug some data on a category page, we can use the logger interface to write something to a file. Open the category page controller, which is in the following file: app/code/Magento/Catalog/Controller/Category/View.php.

    Note

    If you installed Magento with...