
For such situations, logging to console would be ideal. We have a tutorial covering monolog logging for such situations, where you can learn how to send the logs to Retrace.Sometimes you just want something lightweight to display inside the browser for front-end debugging. PHP logging libraries work best when outputting a detailed breakdown of the error stack trace for server-side errors such as database connection into files. These frameworks usually use popular PHP logging libraries such as Monolog. If you prefer to output view variables without distorting the web page, logging to the browser console is betterĪnother thing to note is that PHP developers are increasingly gravitating toward frameworks such as Laravel and Symfony. For this option, we recommend an open-source logging library like Monolog instead of var_dump. Another possible destination for output may be a file in your server. You could write output to the browser web page, but this will likely distort the display. However, when you use var_dump, you need to decide where you want to write the output to. Now, you can log using PHP’s native functions such as var_dump. The second reason is to keep the logging as least intrusive as possible. Since you’ll normally toggle between the two as you write code in the editor and test it on the browser, the most natural place to display log statements is inside the browser. As a PHP developer, you want to work with two applications at most, your favorite code editor or IDE and your browser. There are two primary reasons you want to log to the browser console. 3: How to log to console using JavaScript Why logging to console is a good thing


And you can test it out by writing the same JavaScript console.log command. The browser console will be one of the tabs in the Developer Tools. 2: Developer Tools in Chrome after clicking Inspect 1: How to trigger Developer Tools in Chrome Fig.

To start, open Google Chrome and go to any web page, right-click and choose Inspect to bring up Chrome’s Developer Tools. The information logged includes network requests, JavaScript, CSS, security errors and warnings, as well as errors, warnings and informational messages explicitly logged by JavaScript code running in the page context.įor demonstrations, we’ll use the desktop version of Google Chrome, but you can also perform similar steps in desktop versions of Firefox, Safari and Internet Explorer. The browser console is a way for the browser to log information associated with a specific web page.

First of all, we need to understand what the browser console is.
